本文总结一下在工作中经常用到的adb command
1. adb devices: 查看连接的device
adb devices
List of devices attached
emulator-5554 device
emulator-5555 device
2. 安装apk文件
adb install helloWorld.apk
可以指定Android手机的serial number
adb -s emulator-5555 install helloWorld.apk
3. 卸载apk文件
adb uninstall com.example.MyApp
4. adb start-server
5. adb kill-server, 停止adb server
6. adb pull remote local 将文件从Android设备端拷贝到电脑端
adb pull /sdcard/foo.txt /local/
7. adb push local remote 将文件从电脑端拷贝到Android设备sd卡上
adb push foo.txt /sdcard/foo.txt
8. 删除文件
adb shell rm /sdcard/foo.txt
9. 创建目录
adb shell mkdir -p /sdcard/tmp/test
10. 复制文件
adb shell cp /sdcard/foo.txt /sdcard/tmp
11. adb shell
adb [-d |-e | -s serial_number] shell shell_command
To start an interactive shell on a device use the shell command like this:
adb [-d | -e | -s serial_number] shell
查看系统内存:
adb shell cat /proc/meminfo
查看指定包名应用内存使用情况:
adb shell dumpsys meminfo <package>
To exit an interactive shell, press Control + D or type exit.
12. Call activity manager (am)
am <command>
start [options] intent: start an activity specified by intent
adb shell am start -a android.intent.action.VIEW
启动应用:
adb shell am start -n <pckagename/activity>
停止应用:
adb shell am force-stop <package>
查看所有的activity:
adb shell dumpsys activity
查找当前的activity
adb shell dumpsys activity | findstr 'mainActivity'
13. Call package manager(pm)
adb shell pm list package 列举package
list packages [options] filter Prints all packages, optionally only
those whose package name contains the text in filter. Options:
-f: See their associated file.
-d: Filter to only show disabled packages.
-e: Filter to only show enabled packages.
-s: Filter to only show system packages.
-3: Filter to only show third party packages.
-i: See the installer for the packages.
-u: Also include uninstalled packages.
–user user_id: The user space to query.
清空指定包名对应胡数据和缓存文件:
adb shell pm clear <packagename>
14. 截图
screencap filename
adb shell screencap /sdcard/screen.jpg