#adb #android #tcp #usb

adb_client

Rust ADB (Android Debug Bridge) client library

30 releases (14 stable)

new 2.0.5 Nov 18, 2024
2.0.1 Oct 31, 2024
1.0.7 Sep 28, 2024
1.0.3 Jul 13, 2024
0.1.5 Jan 23, 2022

#159 in Debugging

Download history 72/week @ 2024-07-29 110/week @ 2024-08-05 52/week @ 2024-08-12 16/week @ 2024-08-19 7/week @ 2024-08-26 169/week @ 2024-09-02 181/week @ 2024-09-09 43/week @ 2024-09-16 219/week @ 2024-09-23 50/week @ 2024-09-30 19/week @ 2024-10-07 18/week @ 2024-10-14 194/week @ 2024-10-21 148/week @ 2024-10-28 217/week @ 2024-11-04 180/week @ 2024-11-11

741 downloads per month
Used in adb_cli

MIT license

125KB
3K SLoC

adb_client

MIT licensed Documentation Crates.io Total Downloads

Rust library implementing ADB protocol.

Installation

Add adb_client crate as a dependency by simply adding it to your Cargo.toml:

[dependencies]
adb_client = "*"

Examples

Get available ADB devices

use adb_client::ADBServer;
use std::net::{SocketAddrV4, Ipv4Addr};

// A custom server address can be provided
let server_ip = Ipv4Addr::new(127, 0, 0, 1);
let server_port = 5037;

let mut server = ADBServer::new(SocketAddrV4::new(server_ip, server_port));
server.devices();

Using ADB server as proxy

[TCP] Launch a command on device

use adb_client::{ADBServer, ADBDeviceExt};

let mut server = ADBServer::default();
let mut device = server.get_device().expect("cannot get device");
device.shell_command(["df", "-h"],std::io::stdout());

[TCP] Push a file to the device

use adb_client::ADBServer;
use std::net::Ipv4Addr;
use std::fs::File;
use std::path::Path;

let mut server = ADBServer::default();
let mut device = server.get_device().expect("cannot get device");
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
device.push(&mut input, "/data/local/tmp");

Interacting directly with device

[USB] Launch a command on device

use adb_client::{ADBUSBDevice, ADBDeviceExt};

let vendor_id = 0x04e8;
let product_id = 0x6860;
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
device.shell_command(["df", "-h"],std::io::stdout());

[USB] Push a file to the device

use adb_client::{ADBUSBDevice, ADBDeviceExt};
use std::fs::File;
use std::path::Path;

let vendor_id = 0x04e8;
let product_id = 0x6860;
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
device.push(&mut input, "/data/local/tmp");

Dependencies

~12–38MB
~612K SLoC