Introduction
Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with Android devices. It’s an essential utility for developers, testers, and power users that facilitates a wide variety of device actions—from basic tasks like installing and debugging apps to advanced operations like running shell commands on the device. This cheatsheet provides a comprehensive collection of ADB commands organized by their function to help you navigate Android device management efficiently.
Core ADB Concepts
Components of ADB
- ADB Client: The command-line tool on your computer
- ADB Server: Background service running on your computer
- ADB Daemon (adbd): Background process running on Android devices
Connection Modes
- USB Debugging: Physical connection via USB cable
- Wireless Debugging: Connection over Wi-Fi network
- TCP/IP Debugging: Remote connection using IP address
Getting Started with ADB
Installation and Setup
- Download and install Android SDK Platform Tools
- Add ADB to your system PATH
- Enable Developer Options on your Android device
- Enable USB Debugging in Developer Options
- Connect your device via USB and authorize the connection
Basic Connection Commands
Command | Description |
---|---|
adb devices | List all connected devices |
adb devices -l | List devices with additional details |
adb kill-server | Terminate the ADB server process |
adb start-server | Start the ADB server process |
adb connect <IP>:<PORT> | Connect to a device over Wi-Fi |
adb disconnect <IP>:<PORT> | Disconnect from a Wi-Fi device |
adb usb | Restart ADB in USB mode |
adb tcpip <PORT> | Restart ADB in TCP/IP mode |
adb -s <DEVICE_ID> <COMMAND> | Execute command on specific device |
adb wait-for-device | Block until a device is connected |
App Management Commands
Installation and Uninstallation
Command | Description |
---|---|
adb install <APK_FILE> | Install an APK |
adb install -r <APK_FILE> | Install an APK, replacing existing app |
adb install -s <APK_FILE> | Install APK to SD card |
adb install-multiple <APK_FILES> | Install multiple APKs |
adb uninstall <PACKAGE_NAME> | Uninstall an app |
adb uninstall -k <PACKAGE_NAME> | Uninstall app but keep data/cache |
App Data and Management
Command | Description |
---|---|
adb shell pm list packages | List all installed packages |
adb shell pm list packages -s | List system packages |
adb shell pm list packages -3 | List third-party packages |
adb shell pm clear <PACKAGE_NAME> | Clear app data and cache |
adb shell pm disable <PACKAGE_NAME> | Disable an app |
adb shell pm enable <PACKAGE_NAME> | Enable an app |
adb shell pm path <PACKAGE_NAME> | Get APK path of an app |
adb shell dumpsys package <PACKAGE_NAME> | Get detailed info about an app |
Device Control and System Management
Power Management
Command | Description |
---|---|
adb reboot | Reboot the device |
adb reboot bootloader | Reboot into bootloader/fastboot |
adb reboot recovery | Reboot into recovery mode |
adb reboot sideload | Reboot into sideload mode |
adb shell reboot -p | Power off the device |
adb shell input keyevent 26 | Turn screen on/off |
System Information
Command | Description |
---|---|
adb shell getprop | Get all system properties |
adb shell getprop <PROPERTY> | Get specific system property |
adb shell setprop <PROPERTY> <VALUE> | Set system property |
adb shell settings list system | List all system settings |
adb shell settings get system <SETTING> | Get system setting value |
adb shell settings put system <SETTING> <VALUE> | Set system setting value |
adb shell dumpsys | Dump all system service info |
adb shell dumpsys battery | Get battery information |
adb shell dumpsys cpuinfo | Get CPU information |
adb shell dumpsys meminfo | Get memory usage information |
adb shell dumpsys activity | Get activity information |
adb shell dumpsys window | Get window information |
Device Features and Specifications
Command | Description |
---|---|
adb shell pm list features | List device features |
adb shell wm size | Get screen resolution |
adb shell wm density | Get screen density |
adb shell cat /proc/cpuinfo | Get CPU details |
adb shell cat /proc/meminfo | Get memory details |
adb shell df | Get disk space information |
File Management Commands
File Transfer
Command | Description |
---|---|
adb push <LOCAL> <REMOTE> | Copy file/dir to device |
adb pull <REMOTE> <LOCAL> | Copy file/dir from device |
adb shell ls <PATH> | List directory contents |
adb shell rm <FILE> | Delete a file |
adb shell mkdir <DIRECTORY> | Create a directory |
adb shell touch <FILE> | Create an empty file |
adb shell cp <SOURCE> <DESTINATION> | Copy files |
adb shell mv <SOURCE> <DESTINATION> | Move files |
adb shell cat <FILE> | Display file contents |
Storage Management
Command | Description |
---|---|
adb shell df | Show disk usage |
adb shell du <PATH> | Show directory size |
adb shell mount | Show mounted filesystems |
adb shell ls -la /storage/ | List storage volumes |
adb shell find <PATH> -name "<PATTERN>" | Find files by name |
Debugging and Logging Commands
Logcat Commands
Command | Description |
---|---|
adb logcat | View device logs |
adb logcat -v time | View logs with timestamps |
adb logcat -b all | View all log buffers |
adb logcat *:E | View only error logs |
adb logcat -c | Clear log buffer |
adb logcat > logfile.txt | Save logs to file |
adb logcat -d | Dump logs and exit |
adb logcat <TAG>:<LEVEL> | Filter logs by tag and level |
adb logcat | grep "<TEXT>" | Filter logs by text |
Debugging Commands
Command | Description |
---|---|
adb jdwp | List JDWP processes |
adb forward tcp:<LOCAL> jdwp:<PID> | Forward port for JDWP debugging |
adb shell am start -D -n <PACKAGE>/<ACTIVITY> | Start app in debug mode |
adb shell ps | List running processes |
adb shell top | Show process resource usage |
adb shell monkey -p <PACKAGE> <COUNT> | Stress test an app |
adb bugreport > bugreport.zip | Generate bug report |
Network and Connectivity Commands
Network Information
Command | Description |
---|---|
adb shell netstat | Display network statistics |
adb shell ip addr show | Show IP addresses |
adb shell ifconfig | Network interface configuration |
adb shell ping <HOST> | Ping a host |
adb shell netcfg | Show network configuration |
adb shell dumpsys connectivity | Show connectivity info |
adb shell dumpsys wifi | Show Wi-Fi information |
adb shell dumpsys bluetooth_manager | Show Bluetooth info |
Port Forwarding
Command | Description |
---|---|
adb forward tcp:<LOCAL> tcp:<REMOTE> | Forward local port to device port |
adb forward --list | List all port forwards |
adb forward --remove tcp:<LOCAL> | Remove specific port forward |
adb forward --remove-all | Remove all port forwards |
adb ppp <TUN> <PARAMETERS> | Run PPP over USB |
UI Automation Commands
Input Commands
Command | Description |
---|---|
adb shell input text "<TEXT>" | Type text |
adb shell input keyevent <KEYCODE> | Send keycode |
adb shell input tap <X> <Y> | Tap at coordinates |
adb shell input swipe <X1> <Y1> <X2> <Y2> | Swipe from one point to another |
adb shell input swipe <X1> <Y1> <X2> <Y2> <DURATION> | Swipe with duration |
adb shell input draganddrop <X1> <Y1> <X2> <Y2> | Drag and drop |
adb shell wm overscan <LEFT>,<TOP>,<RIGHT>,<BOTTOM> | Set overscan area |
Screenshots and Screen Recording
Command | Description |
---|---|
adb shell screencap -p /sdcard/screen.png | Take screenshot |
adb pull /sdcard/screen.png | Pull screenshot to computer |
adb shell screenrecord /sdcard/video.mp4 | Record screen (max 3 minutes) |
adb shell screenrecord --time-limit <SECONDS> <FILE> | Record screen with time limit |
adb shell screenrecord --bit-rate <RATE> <FILE> | Record with custom bitrate |
adb shell screenrecord --size <WIDTHxHEIGHT> <FILE> | Record with custom resolution |
Activity and Service Management
Activity Management
Command | Description |
---|---|
adb shell am start -n <PACKAGE>/<ACTIVITY> | Start an activity |
adb shell am startservice <SERVICE> | Start a service |
adb shell am broadcast -a <ACTION> | Send broadcast |
adb shell am force-stop <PACKAGE> | Force stop an app |
adb shell am kill <PACKAGE> | Kill app processes |
adb shell am kill-all | Kill all background processes |
adb shell am stack list | List activity stacks |
adb shell dumpsys activity activities | Show activity stack info |
Intent Commands
Command | Description |
---|---|
adb shell am start -a <ACTION> -d <DATA> | Start activity with action and data |
adb shell am start -a android.intent.action.VIEW -d <URL> | Open URL |
adb shell am start -a android.intent.action.CALL -d tel:<NUMBER> | Make a phone call |
adb shell am start -n <PACKAGE>/<ACTIVITY> --es <EXTRA_KEY> <EXTRA_STRING_VALUE> | Start with string extra |
adb shell am start -n <PACKAGE>/<ACTIVITY> --ei <EXTRA_KEY> <EXTRA_INT_VALUE> | Start with integer extra |
adb shell am start -n <PACKAGE>/<ACTIVITY> --ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> | Start with boolean extra |
Security and Permissions
Permission Management
Command | Description |
---|---|
adb shell pm list permissions -g | List permission groups |
adb shell pm list permissions -d -g | List dangerous permissions |
adb shell pm grant <PACKAGE> <PERMISSION> | Grant a permission |
adb shell pm revoke <PACKAGE> <PERMISSION> | Revoke a permission |
adb shell dumpsys package <PACKAGE> | grep permission | List app permissions |
Security Commands
Command | Description |
---|---|
adb disable-verity | Disable dm-verity checking |
adb enable-verity | Enable dm-verity checking |
adb root | Restart ADB with root permissions |
adb unroot | Restart ADB without root permissions |
adb shell su | Switch to superuser (if available) |
adb shell getenforce | Get SELinux mode |
adb shell setenforce 0 | Set SELinux to permissive mode |
adb shell setenforce 1 | Set SELinux to enforcing mode |
Advanced ADB Shell Commands
Shell Environment
Command | Description |
---|---|
adb shell | Start interactive shell |
adb shell <COMMAND> | Run shell command |
adb shell echo $PATH | Show shell path |
adb shell export <VAR>=<VALUE> | Set environment variable |
adb shell sh -c "<COMMANDS>" | Run multiple commands |
adb exec-out <COMMAND> | Run command and get raw output |
Package Management (PM)
Command | Description |
---|---|
adb shell pm trim-caches <SIZE> | Trim cache to size in MB |
adb shell pm create-user <NAME> | Create a new user |
adb shell pm remove-user <USER_ID> | Remove a user |
adb shell pm get-max-users | Get maximum user count |
adb shell pm list users | List all users |
adb shell pm list features | List device features |
adb shell pm set-install-location <LOCATION> | Set default install location |
Wireless Debugging (Android 11+)
Command | Description |
---|---|
adb pair <IP>:<PORT> <PAIRING_CODE> | Pair with a device |
adb connect <IP>:<PORT> | Connect to paired device |
adb pair-devices | List paired devices |
Common Challenges and Solutions
ADB Connection Issues
Problem | Solution |
---|---|
“adb devices” shows no devices | 1. Check USB cable<br>2. Restart ADB server with adb kill-server followed by adb start-server <br>3. Reinstall USB drivers<br>4. Try different USB port |
“unauthorized” device | 1. Unlock phone<br>2. Confirm USB debugging prompt<br>3. Revoke USB debugging authorizations and try again |
Multiple devices error | Use -s <DEVICE_ID> to specify target device |
Wi-Fi connection drops | 1. Ensure device and computer are on same network<br>2. Use static IP on Android device<br>3. Reconnect using adb connect <IP>:<PORT> |
Common Error Messages
Error | Solution |
---|---|
“device offline” | 1. Reconnect USB cable<br>2. Restart device<br>3. Restart ADB server |
“device not found” | 1. Check USB connection<br>2. Verify device is in proper mode (not in recovery/bootloader) |
“insufficient permissions” | 1. Run ADB as administrator/root<br>2. Check USB device permissions |
“failed to install *.apk” | 1. Check if app is already installed<br>2. Verify APK is not corrupted<br>3. Ensure sufficient storage space |
“command not found” | 1. Update Android SDK Platform Tools<br>2. Check ADB path in environment variables |
Best Practices and Tips
Performance Optimization
- Use
adb shell dumpsys gfxinfo <PACKAGE>
to analyze UI rendering performance - Monitor battery usage with
adb shell dumpsys batterystats
- Check memory usage with
adb shell dumpsys meminfo <PACKAGE>
- Analyze network usage with
adb shell dumpsys netstats
Security Best Practices
- Disable USB debugging when not in use
- Use
adb disconnect
after wireless debugging sessions - Periodically revoke USB debugging authorizations
- Always validate the fingerprint when connecting to a new computer
Workflow Efficiency
- Create shell scripts or aliases for frequently used command sequences
- Use
adb -s <DEVICE_ID>
in scripts to target specific devices - Combine commands with shell pipes for advanced filtering
- Use
adb shell am start-activity -W
to measure app startup time
Time-Saving Tips
- Use
adb shell wm density reset
to reset display density without rebooting - Clear logcat buffer before debugging with
adb logcat -c
- Use
adb bugreport
to collect comprehensive system information - Install multiple APKs at once with
adb install-multiple
Resources for Further Learning
Official Documentation
Useful Tools
- scrcpy – Display and control Android devices from desktop
- ADB-Enhanced – ADB wrapper with additional functionality
- ADB Shell – Terminal emulator for Android
Community Resources
Reference Tables
Common Keycodes for Input Events
Keycode | Description | Command |
---|---|---|
3 | HOME | adb shell input keyevent 3 |
4 | BACK | adb shell input keyevent 4 |
5 | CALL | adb shell input keyevent 5 |
6 | END CALL | adb shell input keyevent 6 |
24 | VOLUME UP | adb shell input keyevent 24 |
25 | VOLUME DOWN | adb shell input keyevent 25 |
26 | POWER | adb shell input keyevent 26 |
27 | CAMERA | adb shell input keyevent 27 |
61 | TAB | adb shell input keyevent 61 |
66 | ENTER | adb shell input keyevent 66 |
67 | DELETE | adb shell input keyevent 67 |
82 | MENU | adb shell input keyevent 82 |
187 | APP SWITCH | adb shell input keyevent 187 |