Here are some of the commands I find useful for Android's adb
. They can be used manually or to automate your build or testing process.
Use this to view all connected devices and list their IDs.
adb devices
If multiple devices are attached, use adb -s DEVICE_ID
to target a specific device.
Use the install
command to install an apk, the optional -r
argument reinstalls and keeps any data if the application is already installed on the device.
adb install -r APK_FILE # example adb install -r com.growingwiththeweb.example
adb uninstall PACKAGE_NAME # example adb uninstall com.growingwiththeweb.example
adb shell am start PACKAGE_NAME/ACTIVITY_IN_PACKAGE adb shell am start PACKAGE_NAME/FULLY_QUALIFIED_ACTIVITY # example adb shell am start -n com.growingwiththeweb.example/.MainActivity adb shell am start -n com.growingwiththeweb.example/com.growingwiththeweb.example.MainActivity
adb shell
Sergei Shvetsov came up with a nice one liner that takes a screenshot with shell screencap
and outputs it to a local directory using perl. Checkout his blog for an explanation.
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
This command sends the event that unlocks the lockscreen on the device.
adb shell input keyevent 82
To show the log stream on your command line.
adb logcat
adb logcat -s TAG_NAME adb logcat -s TAG_NAME_1 TAG_NAME_2 #example adb logcat -s TEST adb logcat -s TEST MYAPP
To show logs of a specific priority warning and above.
adb logcat "*:PRIORITY" # example adb logcat "*:W"
Here are the priority levels:
adb logcat -s TAG_NAME:PRIORITY adb logcat -s TAG_NAME_1:PRIORITY TAG_NAME_2:PRIORITY #example adb logcat -s TEST: W
grep
Alternatively the output of logcat
can be piped to grep
on a system that supports it.
adb logcat | grep "SEARCH_TERM" adb logcat | grep "SEARCH_TERM_1\|SEARCH_TERM_2" #example adb logcat | grep "Exception" adb logcat | grep "Exception\|Error"
logcat
buffer Use this to clear the buffer to remove any old log data.
adb logcat -c