Expand description
§ADB Utils - Android Debug Bridge Utilities for Rust
A comprehensive Rust library for interacting with Android devices through ADB (Android Debug Bridge). This library provides both synchronous and asynchronous interfaces for device management, file operations, shell command execution, and more.
§Features
- Dual API Support: Both blocking and async/await interfaces
- Device Management: Connect, disconnect, and manage multiple devices
- File Operations: Push, pull, list, and manipulate files on devices
- Shell Commands: Execute shell commands with streaming support
- Screen Operations: Screenshots, input simulation, and screen control
- App Management: Install, uninstall, start, and stop applications
- Network Operations: Port forwarding, WiFi control, and network information
- System Information: Device properties, Android version, hardware info
- Logging: Logcat streaming and filtering
§Quick Start
§Blocking API
use radb::prelude::*;
fn main() -> AdbResult<()> {
// Connect to ADB server
let mut client = AdbClient::default();
// Get device list
let devices = client.list_devices()?;
let mut device = devices.into_iter().next().unwrap();
// Execute shell command
let result = device.shell(["echo", "Hello, ADB!"])?;
println!("Output: {}", result);
// Take screenshot
let screenshot = device.screenshot()?;
println!("Screenshot: {}x{}", screenshot.width(), screenshot.height());
Ok(())
}
§Async API
use radb::prelude::*;
use radb::AdbResult;
#[tokio::main]
async fn main() -> AdbResult<()> {
// Connect to ADB server
let mut client = AdbClient::default().await;
// Get device list
let devices = client.list_devices().await?;
let mut device = devices.into_iter().next().unwrap();
// Execute shell command
let result = device.shell(["echo", "Hello, ADB!"]).await?;
println!("Output: {}", result);
// Stream logcat
let mut logcat = device.logcat(true, None).await?;
while let Some(line) = logcat.next().await {
println!("Log: {}", line?);
}
Ok(())
}
§Feature Flags
blocking
: Enable blocking/synchronous API (default)tokio_async
: Enable async/await API with Tokio runtimeserde
: Enable serialization support for data structures
§Error Handling
The library uses a comprehensive error system with specific error types:
use radb::prelude::*;
match device.shell(["invalid_command"]) {
Ok(output) => println!("Success: {}", output),
Err(AdbError::CommandFailed { command, reason }) => {
eprintln!("Command '{}' failed: {}", command, reason);
}
Err(AdbError::DeviceNotFound { serial }) => {
eprintln!("Device '{}' not found", serial);
}
Err(e) => eprintln!("Other error: {}", e),
}
Re-exports§
pub use client::AdbClient;
pub use client::AdbDevice;
pub use errors::AdbError;
pub use errors::AdbResult;
pub use anyhow;
pub use log;
Modules§
- adb
- Main ADB namespace with all core functionality
- beans
- blocking
- Blocking/synchronous API
- builder
- Builder patterns for complex operations
- client
- errors
- info
- Library information Library metadata and version information
- net
- Networking primitives for TCP/UDP communication.
- prelude
- Common imports for ADB utilities
- protocols
- util
- Utility functions for ADB operations
- utils
Macros§
- adb_
bail - 用于链式错误处理的宏
- adb_
context - 便利宏:将anyhow::Result转换为AdbResult
- adb_
ensure - 用于确保条件的宏
- adb_
expect_ device - adb_
shell