A simple Node.js wrapper for the Android Debug Bridge (ADB).
npm install adb-node
import { Adb, AvdManager } from 'adb-node';
async function main() {
const adb = new Adb();
const avdManager = new AvdManager(); // defaults to 'avdmanager' in path, or pass { path: '/path/to/avdmanager' }
// List available AVDs
const avds = await avdManager.listAvds();
console.log('Available AVDs:', avds);
// Create a new AVD (needs a valid system image package installed)
// await avdManager.createAvd({
// name: 'NewAvd',
// package: 'system-images;android-30;google_apis;x86',
// device: 'pixel'
// });
// Delete an AVD
// await avdManager.deleteAvd('NewAvd');
// List connected devices
const devices = await adb.listDevices();
console.log('Connected devices:', devices);
// Get specific device by AVD name (emulator)
const specificEmulator = await adb.getDeviceByAvdName('Pixel_4_API_30');
if (specificEmulator) {
console.log(`Found emulator with AVD name: ${specificEmulator.serial}`);
}
if (devices.length > 0) {
// Get a client for the first device
const device = adb.getDevice(devices[0].id);
// Or get all connected device clients directly
const connectedClients = await adb.getConnectedDevices();
for (const client of connectedClients) {
console.log(`Checking device: ${client.serial}`);
const model = await client.getModel();
console.log(` Model: ${model}`);
}
// Get device info
const model = await device.getModel();
console.log(`Device Model: ${model}`);
// Get AVD name (for emulators)
const avdName = await device.getAvdName();
if (avdName) {
console.log(`AVD Name: ${avdName}`);
}
// Run a shell command
const output = await device.shell('ls -la /sdcard/');
console.log(output);
// Take a screenshot (simplified, needs pull)
// await device.shell('screencap -p /sdcard/s.png');
// await device.pull('/sdcard/s.png', './s.png');
// Input text
await device.inputText('Hello World');
}
}
main().catch(console.error);
- Global ADB commands: List devices, connect/disconnect, start/kill server.
- Device commands: Shell, push, pull, install, uninstall.
- Input: Keyevents, text input.