南尘2251 2018-03-29 1062浏览量
adb 工具即 Android Debug Bridge(安卓调试桥) tools。它就是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互。在某些特殊的情况下进入不了系统,adb 就派上用场啦!
adb devices
主要是用于打印当前连接的所有模拟器或者设备。
adb forward
端口映射,将 PC 端的某端口数据重定向到手机端的一个端口。
adb forward <local> <remote>
adb kill-server
adb connect <host>[:<port>]
需要保证设备的 /system/build.prop 文件中有命令 service.adb.tcp.port=5555
,否则会遭到拒绝。
此处安利一下无限调试设置方法:
- 打开设备的调试模式,允许 USB 以 MTP 模式传输,确保设备和 PC 能正常连接,可以通过
adb shell
或者adb devices
等进行验证。- 确保已连接后,依次执行以下命令:
adb root
adb remount
adb pull /system/build.prop ./
- 在 adb 命令执行的文件夹下的 build.prop 中加入命令
service.adb.tcp.port=5555
- 执行
adb push ./build.prop /system/
后重启设备
结束后断开 USB 连接线,输入 adb connect 设备IP:5555 确认可以正常连接。
adb install [option] <path>
其中的 option 也是比较有讲究的,下面就只说最常用的。
adb install test.apk
直接安装应用adb install -r test.apk
替代存在的应用,不会删除应用数据,用于更新应用特别方便。
其余的不是很常用的就不多提了,感兴趣的可以自行了解。
adb uninstall [options] <package>
两种情况,假设我们的应用 APP 包名是 com.example.application
adb uninstall com.example.application
直接删除应用和所有数据adb uninstall -k com.example.application
删除应用,但会保留应用数据和缓存数据。
adb shell pm list packages [options] <FiLTER>
其他的过滤方式和限定条件这里也不举例了。
adb shell pm path <package>
adb shell pm clear <package>
adb pull <remote> [local]
其中 <remote> 代表文件在设备中的地址,[local] 代表存放目录。
adb push <local> <remote>
adb shell ls [options] <directory>
cd
差不多,主要用于切换目录。adb shell cd <directory>
adb shell rm [options] <file or directory>
adb shell mkdir [options] <directory name>
adb shell touch [options] <file>
adb shell pwd
adb shell cp [options] <source> <dest>
adb shell mv [options] <source> <dest>
adb shell netstat
主要用于网络统计。
adb shell ping
没啥好说的,和 PC 的 ping 命令一样的。
adb shell netcfg
通过配置文件配置和管理网络连接。
adb shell netcfg [<interface> {dhcp|up|down}]
adb shell ip [OPTIONS] OBJECT
adb logcat [options] [filter-specs]
当然可以像 Android Studio 一样只打印固定的日志
adb logcat *:V
lowest priority, filter to only show Verbose leveladb logcat *:D
filter to only show Debug leveladb logcat *:I
filter to only show Info leveladb logcat *:W
filter to only show Warning leveladb logcat *:E
filter to only show Error leveladb logcat *:F
filter to only show Fatal leveladb logcat *:S
Silent, highest priority, on which nothing is ever printed
adb logcat -b <Buffer>
adb logcat -b radio
View the buffer that contains radio/telephony related messages.adb logcat -b event
View the buffer containing events-related messages.adb logcat -b main
defaultadb logcat -c
Clears the entire log and exits.adb logcat -d
Dumps the log to the screen and exits.adb logcat -f test.logs
Writes log message output to test.logs .adb logcat -g
Prints the size of the specified log buffer and exits.adb logcat -n <count>
*Sets the maximum number of rotated logs to <count>. *
adb shell dumpsys [options]
其中有个非常好用的是,当你在新接触一个项目的时候,不熟悉项目流程,此时正好可以用这个直接定位到你的 Activity 位置。
adb shell dumpsys activity activities
如图,直接在打印出来内容的后半段找到了当前 Activity 的定位,是 NewLoginActivity
。
adb shell screencap <filename>
结合前面的 pull 命令,就可以让我们轻松拿到屏幕截图。
adb shell screencap /sdcard/test.png
截图存放adb pull /sdcard/test.png
取到 PC 当前文件夹
adb shell screencord /sdcard/test.mp4
这个还可以对大小 size 和 时间做限制,感兴趣的可以自行了解。
adb root
获取 root 权限。
adb sideload
adb shell ps
打印进程状态。
adb shell top
展现上层 CPU 进程信息。
adb shell getprop
获取 Android 系统服务属性
adb shell setprop
设置服务属性。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
集结各类场景实战经验,助你开发运维畅行无忧