Overview
Android Debug Bridge (adb)就是command调试工具,可以让你与device连接。比如在PC上用命令控制Android Device。
那PC上要装驱动以便能识别到设备,Android Device需要是开发者模式,并且enable USB debugging。成功的话,使用adb devices
命令,可以看到看到已连接的device。
Command
下面列出我目前长用到的adb命令,后面会直接把google资料的都贴过来。
# 这里可以直接把apk拖到Terminal
adb install [apk_name]
# when you install a test APK(For example: Cts Verify里面的一些apk)
adb install -t [apk_name]
# launcher activity
adb shell am start -n {package name}/{package name}.activity
# look activity task
adb shell dumpsys activity activities
# look service list
adb shell service list
# look pm features list
adb shell pm list features
# input [touchscreen|touchpad|touchnavigation] tap
adb shell input tap 100 100
# input [touchscreen|touchpad|touchnavigation] swipe [duration(ms)]
adb shell input swipe 100 100 200 200 300
# root
adb root
# Start a remote interactive shell in the target device
adb shell
# To copy a file or directory and its sub-directories to the device
# File from PC to Device, For example: adb push foo.txt /sdcard/foo.txt
adb push [local remote]
# File from Device to PC, For example: adb pull /sdcard/screen.png
adb pull [remote local]
# 看logcat,经常是adb logcat > log.log 直接在文件中看
adb logcat
# screenrecord step
# step1: root
# step2: remount(get read&write permission)
# step3: screenrecord command
# step4: sync
# step5: devices -> PC
adb root
adb remount
adb shell screenrecord /sdcard/demo.mp4
adb shell sync
adb pull /sdcard/demo.mp4 E:\xxx
Global options
General commands
Networking commands
File transfer commands
App installation commands
Backup and restore commands
Debug commands
Security commands
Scripting commands
Internal debugging commands
Shell commands
Call activity manager(am)
For example:
adb shell am start -a android.intent.action.VIEW
Call package manager (pm)
For example:
adb shell pm uninstall com.example.MyApp
Call device policy manager (dpm)
adb shell dpm command