Some useful Android adb commands to share

  • 2020-06-15 10:09:42
  • OfStack

Here are 1 of the ADB commands I found useful. You can use either manual or automated build and test procedures.

Check the equipment


adb devices

If multiple devices are connected, use use ES9en-ES10en DEVICE_ID to connect to the target device

Install the application

Install 1 apk package using the install command. If the application is already installed on the device, re-install and retain the original application data using -ES19en


adb install -r APK_FILE #example
adb install -r com.feiliu.wjbd

Uninstall 1 application


adb uninstall APK_FILE #example
adb uninstall com.feiliu.wjbd

Launch 1 page


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.feiliu.wjbd/.MainActivity
adb shell am start -n com.feiliu.wjbd/com.feiliu.wjbd.MainActivity

Enter the shell interface of the device


adb shell

screenshots

Sergei Shvetsov came up with a nice way to get a screenshot and use shell screencap to output to the local directory via perl. Check out his blog for more details


adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

XieBing

This command sends an unscreen-release event to the lock screen device


adb shell input keyevent 82

The log

The command line shows Log


adb logcat

Filtered by tagname

adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2 #example
adb logcat -s TEST
adb logcat -s TEST MYAPP

Preferred filtering

Displays logs with 1 specific priority warning and above.


adb logcat "*:PRIORITY" # example
adb logcat "*:W"

Priority:

V - Rules (Minimum priority)
D - debugging
I information -
W - warning
E error -
Deadly F -
S - Silent (highest priority, no information will be printed)

Use grep filtering

This is similar to using pipe command 1 on Linux and requires system support


adb install -r APK_FILE #example
adb install -r com.feiliu.wjbd
0
Clear log block

Use to clean up old logs


adb logcat -c


Related articles: