Essential ADB Commands for Android Developers
Essential ADB Commands for Android Developers
Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run specific commands on a device.
Here is a cheat sheet of the most common and useful ADB commands.
Device Connection
1. List Connected Devices
Check which devices are connected and recognized by ADB.
adb devices
Output:
List of devices attached
emulator-5554 device
0a388e93 device
2. Connect via Wi-Fi
To connect to a device over the network (requires device IP).
adb connect 192.168.1.5:5555
App Management
3. Install an APK
Installs an app from your computer to the device.
adb install path/to/app.apk
Flags:
-r: Reinstall (replace existing app while keeping data).-g: Grant all runtime permissions.
4. Uninstall an App
Removes an app using its package name.
adb uninstall com.example.myapp
5. List Installed Packages
See all apps installed on the device.
adb shell pm list packages
Filter with grep:
adb shell pm list packages | grep "google"
File Transfer
6. Push File (PC -> Device)
Copy a file from your computer to the device.
adb push local_file.txt /sdcard/Download/
7. Pull File (Device -> PC)
Copy a file from the device to your computer.
adb pull /sdcard/Download/remote_file.txt .
Debugging & Logging
8. View Logcat
View real-time system logs. Essential for debugging crashes.
adb logcat
Clear buffer:
adb logcat -c
9. Take a Screenshot
Capture the device screen and save it to the device’s storage.
adb shell screencap -p /sdcard/screenshot.png
Then pull it:
adb pull /sdcard/screenshot.png
10. Record Screen
Record a video of the device screen.
adb shell screenrecord /sdcard/demo.mp4
Advanced Shell Commands
11. Enter Device Shell
Open a remote shell on the device.
adb shell
12. Input Text
Type text into a focused input field on the device (useful for automation).
adb shell input text "Hello World"
13. Simulate Key Events
Press the “Home” button via command line.
adb shell input keyevent 3
(Key 3 is HOME, 4 is BACK, 26 is POWER)
Summary table
| Command | Description |
|---|---|
adb devices |
List connected devices |
adb install <apk> |
Install an application |
adb logcat |
View system logs |
adb push <local> <remote> |
Copy file to device |
adb pull <remote> <local> |
Copy file from device |
adb shell |
Open interactive shell |
Mastering these commands will significantly speed up your Android development and debugging workflow!