adbshell
A minimal, zero-overhead Rust wrapper around the adb command-line tool.
adbshell exposes [AdbShell], a stateless unit-struct whose associated
functions cover the ADB operations most commonly needed by desktop Android
companion apps: device discovery, system-property queries, file push, JAR
execution, and reverse-tunnel management. Every call spawns a fresh adb
subprocess — no persistent daemon connection is maintained.
Features
- Device discovery: serial number, connection state, screen size and orientation.
- System property queries via
getprop. - File transfer with
adb push. - Reverse-tunnel setup and teardown (
adb reverse). app_processJAR execution for launching Android server processes.- Optional per-call timeout support (backed by
wait-timeout). - No async runtime required — pure
stdthreads.
Quick start
Add to your Cargo.toml:
[]
= { = "3rd-party/adbshell" }
use ;
verify_adb_available.expect;
let serial = get_device_serial.expect;
let sdk = get_prop.unwrap;
println!;
let state = get_device_state.unwrap;
println!;
API overview
| Function | Description |
|---|---|
AdbShell::verify_adb_available() |
Verify adb is installed and in PATH |
AdbShell::get_device_serial() |
Return the first connected device serial |
AdbShell::get_device_state(serial) |
Return Connected, Disconnected, or Unknown |
AdbShell::get_prop(serial, key) |
Read an Android system property |
AdbShell::get_android_version(serial) |
Return the API level as u32 |
AdbShell::get_platform(serial) |
Return board/hardware platform string |
AdbShell::get_physical_screen_size(serial) |
Return (width, height) in pixels |
AdbShell::get_screen_orientation(serial) |
Return orientation 0–3 |
AdbShell::get_ime_state(serial) |
Return whether the soft keyboard is visible |
AdbShell::push_file(serial, src, dst) |
Push a local file to the device |
AdbShell::execute_jar(serial, jar, …) |
Launch a JAR via app_process |
AdbShell::setup_reverse_tunnel(serial, …) |
Create an ADB reverse tunnel |
AdbShell::remove_reverse_tunnel(serial, …) |
Remove an ADB reverse tunnel |
Error handling
All functions return AdbResult<T> (an alias for Result<T, AdbError>).
Requirements
adb(Android platform-tools) must be installed and inPATH.- Rust 1.85+
License
Licensed under either of
at your option.