Mac 下的 iTerm 终端真是炫酷到爆,而且超级好用,在调试 Android 应用的时候,在终端下使用一些 ADB 命令,能帮助我们提高不少效率,下面就整理常见的一些 ADB 操作。
adb 开启 / 关闭 一般 adb 挂掉时,可以用下面第一句重新开启
1 2 adb start-server adb kill-server
adb 查看设备/指定设备
1 2 3 4 5 6 7 8 9 adb devices List of devices attached 8eeeadda device adb -s 8eeeadda shell
adb 安装/卸载 apk
1 2 3 4 5 6 7 8 9 10 adb install hello.apk adb install -r hello.apk adb uninstall com.clear.hello adb uninstall -k com.clear.hello
adb 截图并发送到电脑
1 2 3 4 5 6 7 8 9 adb shell /system/bin/screencap -p /sdcard/screenshot.png adb pull /sdcard/screenshot.png /Users/mjd/Downloads/screenshot.png adb shell rm /sdcard/screenshot.png
adb 包管理 & 清除应用数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 adb shell pm list packages adb shell pm list packages -s adb shell pm list packages -3 adb shell pm list packages qq or adb shell pm list packages | grep qq adb shell pm clear com.clear.hello
adb 查看前台 Activity,正在运行的 Service
1 2 3 4 5 6 7 adb shell dumpsys activity activities | grep mFocusedActivity or adb shell dumpsys window | grep mCurrentFocus adb shell dumpsys activity services
adb 启动 Activity ,启动 Service,发送 Broadcast
1 2 3 4 5 6 7 8 9 10 11 adb shell am start -n com.tencent.mm/.ui.LauncherUI adb shell am startservice -n com.tencent.mm/.plugin.accountsync.model.AccountAuthenticatorService adb shell am broadcast -a android.intent.action.BOOT_COMPLETED adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.clear.hello/.BootCompletedReceiver
adb 查看 app 内存占用
1 2 3 4 5 6 adb shell dumpsys meminfo <package_name> adb shell procrank | grep <package_name>
adb 查看进程占用
1 2 3 4 5 6 adb shell top -n 1 -d 0.5 | grep PID adb shell dumpsys cpuinfo | grep <package_name>
参考文章 awesome-adb
Title: ADB 常见命令
Author: mjd507
Date: 2016-12-11
Last Update: 2024-01-27
Blog Link: https://mjd507.github.io/2016/12/11/ADB-Commands/
Copyright Declaration: This station is mainly used to sort out incomprehensible knowledge. I have not fully mastered most of the content. Please refer carefully.