RxShell
Easy shell access for Android apps using RxJava.
Install / Use
/learn @d4rken/RxShellREADME
RxShell
A library that helps your app interact with shells on Android.
Quickstart
Include the library in your modules build.gradle file:
implementation 'eu.darken.rxshell:<insert-latest-release>'
Now your project is ready to use the library, let's quickly talk about a few core concepts:
- You construct a shell using
RxCmdShell.builder(). - The shell has to be opened before use (
shell.open()), which will launch the process and give you aRxCmdShell.Sessionto work with. - Build your commands with
Cmd.builder("your command"). - Commands are run with
session.submit(command),cmd.submit(session)orcmd.execute(session). - Remember to
close()the session to release resources.
Examples
Single-Shot execution
If you pass a shell builder to the command it will be used for a single shot execution.
A shell is created and opened, used and closed.
Cmd.execute(...) is shorthand for Cmd.submit(...).blockingGet(), so don't run it from a UI thread.
Cmd.Result result = Cmd.builder("echo hello").execute(RxCmdShell.builder());
Reusing a shell
If you want to issue multiple commands, you can reuse the shell which is faster and uses less resources.
RxCmdShell.Session session = RxCmdShell.builder().build().open().blockingGet();
// Blocking
Cmd.Result result1 = Cmd.builder("echo straw").execute(session);
// Async
Cmd.builder("echo berry").submit(session).subscribe(result -> Log.i("ExitCode: " + result.getExitCode()));
shell.close().blockingGet();
The default shell process is launched using sh, if you want to open a root shell (using su) tell the ShellBuilder!
Cmd.Result result = Cmd.builder("echo hello").execute(RxCmdShell.builder().root(true));
Checking root access
// General info
new RootContext.Builder(getContext()).build().subscribe(c -> {/* c.getRoot().getState() */});
// Just root state
Root root = new Root.Builder().build().blockingGet();
if(root.getState() == Root.State.ROOTED) /* yay */
Used by
- SD Maid, which was also the motivation for this library.
Alternatives
While this is obviously :^) the best library, there are alternatives you could be interested in:
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
