ADB 工具位于 SDK 的 platform-tools 目录下,因此在命令行中使用 ADB 的时候,需要通过 cd 命令,切换到该目录下,或者将 ADB 添加到环境变量中直接使用。配置好了,在命令行中可以输入下面命令。
adb version
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
下面介绍一些我总结的常用的 ADB 命令:
android list target
显示系统中全部 Android 平台adb devices
查看相连的 Android 设备-
adb install
安装 apk 程序到手机,有时候同时连接多个设备的话,我们需要指定安装的目标设备adb install -s 192.168.1.7:5555 install *.apk
adb push <local> <remote>
将文件推到手机存储adb pull <remote> <local>
从手机获取文件-
adb shell
可以进入设备的命令模式,可以执行 Linux 上的大多命令- 查看log
logcat | grep "***"
- 删除应用
cd system/app
rm *.apk
- 查看系统盘符
adb shell df
- 输出已经安装的应用
adb shell pm list packages -f
- 模拟按键输入
adb shell input keyevent 3
对用的数字可以网上搜一下,下面列举几个常用的 3-home,4-back,82-menu - 模拟滑动输入
adb shell input touchscreen <x1> <y1> <x2> <y2>
- 查看运行状态,比如列出 activity 的运行状态,同时过滤 "tencent" 关键字
- 查看log
hero2qltechn:/ $ dumpsys activity activities | grep "tencent"
* TaskRecord{60aa400d0 #446 A=com.tencent.mobileqq U=0 StackId=1 sz=3}
userId=0 effectiveUid=u0a191 mCallingUid=u0a191 mUserSetupComplete=true mCallingPackage=com.tencent.mobileqq
affinity=com.tencent.mobileqq
intent={flg=0x10000000 cmp=com.tencent.mobileqq/com.dataline.activities.LiteActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 }}
realActivity=com.tencent.mobileqq/com.dataline.activities.LiteActivity
Activities=[ActivityRecord{f66f294d0 u0 com.tencent.mobileqq/com.dataline.activities.LiteActivity t446}, ActivityRecord{e4d4e42d0 u0 com.tencent.mobileqq/.filemanager.fileviewer.FileBrowserActivity t446}, ActivityRecord{36d8eb4d0 u0 com.tencent.mobileqq/.activity.GesturePWDUnlockActivity t446}]
* Hist #2: ActivityRecord{36d8eb4d0 u0 com.tencent.mobileqq/.activity.GesturePWDUnlockActivity t446}
packageName=com.tencent.mobileqq processName=com.tencent.mobileqq
launchedFromUid=10191 launchedFromPackage=com.tencent.mobileqq userId=0
app=ProcessRecord{fd39030 13405:com.tencent.mobileqq/u0a191}
Intent { flg=0x40000 cmp=com.tencent.mobileqq/.activity.GesturePWDUnlockActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }
frontOfTask=false task=TaskRecord{60aa400d0 #446 A=com.tencent.mobileqq U=0 StackId=1 sz=3}
taskAffinity=com.tencent.mobileqq
realActivity=com.tencent.mobileqq/.activity.GesturePWDUnlockActivity
baseDir=/data/app/com.tencent.mobileqq-1/base.apk
dataDir=/data/user/0/com.tencent.mobileqq
* Hist #1: ActivityRecord{e4d4e42d0 u0 com.tencent.mobileqq/.filemanager.fileviewer.FileBrowserActivity t446}
packageName=com.tencent.mobileqq processName=com.tencent.mobileqq
launchedFromUid=10191 launchedFromPackage=com.tencent.mobileqq userId=0
app=ProcessRecord{fd39030 13405:com.tencent.mobileqq/u0a191}
Intent { flg=0x40000 cmp=com.tencent.mobileqq/.filemanager.fileviewer.FileBrowserActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }
frontOfTask=false task=TaskRecord{60aa400d0 #446 A=com.tencent.mobileqq U=0 StackId=1 sz=3}
taskAffinity=com.tencent.mobileqq
- package 管理信息
pm list packages -f
- 启动一个 activity
adb shell am start -n 包名 + 类名
- 录制屏幕
adb shell screenrecord /sdcard/record.mp4
- 重新启动
adb reboot