| Crates.io | rust-droid |
| lib.rs | rust-droid |
| version | 0.1.1 |
| created_at | 2025-11-11 11:58:29.677392+00 |
| updated_at | 2025-11-11 12:42:47.475129+00 |
| description | A powerful UI automation framework for Android. |
| homepage | |
| repository | https://github.com/jhq223/rust-droid |
| max_upload_size | |
| id | 1927099 |
| size | 104,555 |
A powerful and fluent UI automation framework for Android, written in Rust. Inspired by popular tools like Airtest and uiautomator2.
rust-droid allows you to write simple, readable scripts to automate actions on Android devices using image recognition.
USB Debugging: Enable "USB debugging" in the "Developer options" on your Android device.
Add rust-droid to your Cargo.toml:
[dependencies]
rust-droid = "0.1.0"
anyhow = "1.0"
env_logger = "0.11"
Here is a simple script that finds the "Settings" icon on the home screen, taps it, waits for the page to load, and takes a screenshot.
// examples/simple_script.rs
use rust_droid::{Droid, DroidConfig, Target, models::KeyCode};
use std::path::PathBuf;
use std::time::Duration;
fn main() -> anyhow::Result<()> {
// Initialize a logger to see internal logs from rust-droid.
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
// 1. Create a Droid instance.
// It will automatically connect to the first available device.
println!("Connecting to device...");
let mut droid = Droid::new(DroidConfig::default())?;
println!("Connection successful!");
// 2. Define the target image we want to find.
let settings_icon_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("examples/assets/settings_icon.png");
let settings_icon = Target::Image(settings_icon_path);
// 3. Wait for the settings icon to appear on the screen.
// The `execute()` method returns the coordinates where the icon was found.
println!("Waiting for settings icon...");
let icon_position = droid.wait_for(settings_icon).timeout(Duration::from_secs(10)).execute()?;
println!("Settings icon found at: {:?}", icon_position);
// 4. Tap the icon. `icon_position` is a `Point`, which can be converted into a `Target`.
println!("Tapping the settings icon...");
droid.touch(icon_position.into()).execute()?;
// 5. Wait for the settings page to load.
droid.sleep(Duration::from_secs(2));
// 6. Take a snapshot of the current screen.
let snapshot_path = "settings_page.png";
println!("Taking a snapshot and saving to '{}'...", snapshot_path);
droid.snapshot(snapshot_path)?;
println!("Snapshot saved successfully.");
// 7. Press the back button to return to the home screen.
println!("Pressing the back button...");
droid.keyevent(KeyCode::Back).execute()?;
println!("Script finished successfully!");
Ok(())
}
Contributions are welcome! Please feel free to open an issue or submit a pull request.
This project is licensed under the Apache-2.0 License.