| name | android |
| description | Use when working with Android devices via ADB - connecting devices, running shell commands, installing apps, debugging, taking screenshots, UI automation, viewing logs, analyzing crashes, or exploring system internals. Triggers on "adb", "logcat", "install apk", "debug android", "android device", "shell command", "screenshot", "dumpsys", "crash", "ANR". |
Android Device Mastery
This skill covers everything about interacting with Android devices via ADB and shell commands.
Device Connection
Check Connected Devices
adb devices -l
Output shows serial, status, and device info. Common statuses:
device - Connected and authorized
unauthorized - Accept USB debugging prompt on device
offline - Connection issues, try adb kill-server && adb start-server
Wireless Debugging
Android 11+ (Recommended):
- Enable Wireless debugging in Developer Options
- Tap "Pair device with pairing code"
- Run:
adb pair <ip>:<pairing_port> and enter the code
- Then:
adb connect <ip>:<connection_port>
Legacy (requires USB first):
adb tcpip 5555
adb connect <device_ip>:5555
Multiple Devices
Always specify device with -s:
adb -s <serial> shell
adb -s emulator-5554 install app.apk
Shell Commands
Interactive Shell
adb shell
adb shell <command>
adb shell "cmd1 && cmd2"
Essential Commands
getprop ro.product.model
getprop ro.build.version.release
getprop ro.build.version.sdk
ls -la /sdcard/
cat /path/to/file
cp /source /dest
rm /path/to/file
ps -A | grep <name>
pidof <package_name>
top -n 1 -m 10
Safe Output Limiting
For commands with potentially large output:
adb shell "logcat -d | head -500"
adb shell "dumpsys activity | head -200"
App Management
Install/Uninstall
adb install app.apk
adb install -r app.apk
adb install -g app.apk
adb install -r -g app.apk
adb uninstall com.example.app
adb uninstall -k com.example.app
Start/Stop Apps
adb shell monkey -p com.example.app -c android.intent.category.LAUNCHER 1
adb shell am start -n com.example.app/.MainActivity
adb shell am start -n com.example.app/.Activity \
-a android.intent.action.VIEW \
-d "myapp://page/123" \
--es "key" "value"
adb shell am force-stop com.example.app
adb shell pm clear com.example.app
List Packages
adb shell pm list packages
adb shell pm list packages -3
adb shell pm list packages | grep term
adb shell pm path com.example.app
adb shell dumpsys package com.example.app
Permissions
adb shell pm grant com.example.app android.permission.CAMERA
adb shell pm revoke com.example.app android.permission.CAMERA
adb shell dumpsys package com.example.app | grep permission
File Operations
Push/Pull Files
adb push local_file.txt /sdcard/
adb pull /sdcard/remote_file.txt ./
adb push local_dir/ /sdcard/target/
adb pull /sdcard/dir/ ./local/
Access App Data (Debuggable Apps)
adb shell run-as com.example.app ls files/
adb shell run-as com.example.app cat shared_prefs/prefs.xml
adb shell run-as com.example.app sqlite3 databases/app.db ".tables"
UI Automation
Input Commands
adb shell input tap 500 800
adb shell input swipe 500 1500 500 500 300
adb shell input text "hello"
adb shell input keyevent KEYCODE_HOME
adb shell input keyevent KEYCODE_BACK
adb shell input keyevent KEYCODE_ENTER
adb shell input keyevent KEYCODE_POWER
adb shell input keyevent KEYCODE_VOLUME_UP
Common Keycodes
| Code | Key | Code | Key |
|---|
| 3 | HOME | 4 | BACK |
| 24 | VOL_UP | 25 | VOL_DOWN |
| 26 | POWER | 66 | ENTER |
| 67 | DEL | 82 | MENU |
Screenshots & Recording
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png
adb exec-out screencap -p > screen.png
adb shell screenrecord /sdcard/video.mp4
adb shell screenrecord --time-limit 10 /sdcard/video.mp4
UI Hierarchy
adb shell uiautomator dump /sdcard/ui.xml
adb pull /sdcard/ui.xml
Debugging & Logs
Logcat Essentials
adb logcat -d
adb logcat -t 100
adb logcat ActivityManager:I *:S
adb logcat --pid=$(adb shell pidof -s com.example.app)
adb logcat -b crash
Priority levels: V(erbose), D(ebug), I(nfo), W(arn), E(rror), F(atal), S(ilent)
Common Debug Patterns
adb logcat *:E | grep -E "(Exception|Error|FATAL)"
adb logcat ActivityManager:I ActivityTaskManager:I *:S
adb logcat art:D dalvikvm:D *:S | grep -i "gc"
Memory Analysis
adb shell dumpsys meminfo com.example.app
Key metrics:
- PSS: Proportional memory use (compare apps with this)
- Private Dirty: Memory exclusive to process
- Heap: Java/Native heap usage
Crash Analysis
adb shell cat /data/anr/traces.txt
adb shell ls /data/tombstones/
adb logcat -b crash -d
System Inspection
dumpsys Services
adb shell dumpsys -l
adb shell dumpsys activity
adb shell dumpsys package <pkg>
adb shell dumpsys battery
adb shell dumpsys meminfo
adb shell dumpsys cpuinfo
adb shell dumpsys window displays
adb shell dumpsys connectivity
System Properties
adb shell getprop
adb shell getprop | grep <filter>
getprop ro.product.model
getprop ro.build.fingerprint
getprop ro.serialno
getprop sys.boot_completed
Settings
adb shell settings get global airplane_mode_on
adb shell settings put system screen_brightness 128
adb shell settings list global
Reboot Commands
adb reboot
adb reboot recovery
adb reboot bootloader
adb reboot sideload
adb reboot-bootloader
Troubleshooting
Device not found:
adb kill-server && adb start-server
Unauthorized:
- Check USB debugging is enabled
- Revoke USB debugging authorizations in Developer Options, reconnect
Multiple devices error:
- Use
-s <serial> to specify device
Command not found (on device):
- Some commands require root or are version-specific
- Try
/system/bin/<cmd> or check if command exists
Quick Reference
| Task | Command |
|---|
| List devices | adb devices -l |
| Install app | adb install -r -g app.apk |
| Start app | adb shell monkey -p pkg -c android.intent.category.LAUNCHER 1 |
| Stop app | adb shell am force-stop pkg |
| Screenshot | adb exec-out screencap -p > screen.png |
| Logs | adb logcat -d -t 100 |
| Shell | adb shell |
| Push file | adb push local /sdcard/ |
| Pull file | adb pull /sdcard/file ./ |
| Tap | adb shell input tap X Y |
| Back | adb shell input keyevent 4 |
| Home | adb shell input keyevent 3 |
For deep dives into specific topics, see references/deep-dive.md.