Expand description
Async ADB wire protocol client over TCP.
Talks directly to the ADB server (localhost:5037) using the
ADB protocol
without spawning any child processes.
§Quick start
use adb_wire::AdbWire;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let adb = AdbWire::new("emulator-5554");
// Run a command — returns stdout, stderr, and exit code
let result = adb.shell("getprop ro.build.version.sdk").await.unwrap();
println!("SDK version: {}", result.stdout_str());
// Check exit status
let result = adb.shell("ls /nonexistent").await.unwrap();
if !result.success() {
eprintln!("exit {}: {}", result.exit_code, result.stderr_str());
}
// Fire-and-forget (returns immediately, command runs on device)
adb.shell_detach("input tap 500 500").await.unwrap();
// Stream output incrementally (e.g. logcat)
use tokio::io::{AsyncBufReadExt, BufReader};
let stream = adb.shell_stream("logcat -d").await.unwrap();
let mut lines = BufReader::new(stream).lines();
while let Some(line) = lines.next_line().await.unwrap() {
println!("{line}");
}
// File transfer
adb.push_file("local.txt", "/sdcard/remote.txt").await.unwrap();
adb.pull_file("/sdcard/remote.txt", "downloaded.txt").await.unwrap();
// Check if a remote file exists
let st = adb.stat("/sdcard/remote.txt").await.unwrap();
println!("exists={} size={}", st.exists(), st.size);
// Install an APK
adb.install("app.apk").await.unwrap();
}§Host commands
Commands that target the ADB server (not a specific device) are free functions:
use adb_wire::{list_devices, DEFAULT_SERVER};
#[tokio::main(flavor = "current_thread")]
async fn main() {
for (serial, state) in list_devices(DEFAULT_SERVER).await.unwrap() {
println!("{serial}\t{state}");
}
}Structs§
- AdbWire
- Async ADB wire protocol client bound to a specific device.
- DirEntry
- Entry from a remote directory listing.
- Remote
Stat - File metadata returned by
AdbWire::stat. - Shell
Output - Output from a shell command, with separated stdout/stderr and exit code.
- Shell
Stream - Streaming reader for shell command output.
Enums§
- Error
- Error type for ADB wire protocol operations.
Constants§
- DEFAULT_
SERVER - Default ADB server address (
127.0.0.1:5037).
Functions§
- host_
command - Send a host command to an ADB server and read the length-prefixed response.
- list_
devices - List connected devices. Returns
(serial, state)pairs.