adb QuickView
Android Debug Bridge
Android 交互的命令行工具
使用大全:awesome-adb
adb C/S
adb 命令会从命令行调用客户端
服务器/adbd(daemon) 在移动设备上
Installation
有两种安装方式
- 通过 Android Studio 下载 Android SDK 后
~/Library/Android/sdk/platform-tools/路径下 会有 adb 等工具 然后ln -s ~/Library/Android/sdk/platform-tools/adb /usr/bin/adb就可以使用 adb 了 - 自行下载
- 在此处手动下载
- 使用系统包管理器下载
- Windows - winget
- macOS - homebrew
- Debian/Ubuntu - apt
- ...
adb client/server 版本不匹配
都可以控制客户端版本去解决问题 使用第一种方法也许能更好避免该问题的发生
adb common
-s deviceId指定设备
- local: client
- remote: server
| category | cmd | example |
|---|---|---|
| package | install | adb install /path/to/apk |
| uninstall | adb uninstall appId | |
| log | logcat | adb logcat |
| server | start-server | |
| stop-server | ||
| devices | adb devices [-a] | |
| files transfer | push | adb push local remoteadb push foo.txt /sdcard/foo.txt |
| pull | adb pull remote local | |
| port forward | forward | adb forward tcp:6100 local:logd |
adb shell
执行设备上的 (remote)shell
adb shell单独使用即是进入 remote shell
和其他子命令一起使用是 使用 shell 执行命令并退出
- am : activity manager
- pm : package manager
- screencap:
screencap /remote/path/to/save.png - screenrecord:
screenrecord /remote/path/to/save.mp4(无法同时录制音频和视频) - sqlite3
am
- start/startservice/broadcast intent
- force-stop/kill package
- kill-all
intent usage
intent
adb shell am start -a android.intent.action.VIEW
| type | value | example |
|---|---|---|
-a | action | android.intent.action.VIEW |
-d | data_uri | |
-t | mime_type | image/png |
-c | category | android.intent.category.APP_CONTACTS |
-n | component | com.example.app/.MainActivity |
pm
主要命令
- list
- packages [filter]
-d:进行过滤以仅显示已停用的软件包-e:进行过滤以仅显示已启用的软件包-s:进行过滤以仅显示系统软件包-3:进行过滤以仅显示第三方软件包-i:查看软件包的安装程序-u:也包括已卸载的软件包
- permissions/permission-groups
- features
- libraries
- users
- packages [filter]
- install/uninstall
- enable/disable 启用/停用 软件包或组件
grant/revoke package permissionpath package包的APK路径