Android调试工具ADB

ADB简介

adb(android debug bridge),即调试Android设备的桥梁,可以管理、调试模拟机或者真机,是一个C/S架构的应用程序,由三部分组成。

  1. adb client (adb 客户端) 在PC上运行;
  2. adb server (adb 服务端) 在PC上运行,ADB Server检测USB接口何时连接或者移除设备,管理着adb client和adb daemon的通信。它维护着一个“已连接的设备的链表”,并且为每一个设备标记了一个状态:offline,bootloader,recovery或者online;Server一直在做一些循环和等待,以协调client和Server还有daemon之间的通信;
  3. adb daemon (adb 守护进程) 在Emulator或Device上运行;

基本命令

命令的语法格式为

adb [-d|-e|-s <serialNumber>] <command>

其中,[-d|-e|-s serialNumber]用来指定设备。

adb只能对一个设备执行命令,当有设备和模拟器的数量大于1时,未指定设备执行命令时会报错;
解决的方法是指定一个设备,有三种方式:

  • -d
    如果有多个模拟器和一个usb设备,就使用-d;
  • -e
    如果有多个usb设备和一个模拟器,就使用-e;
  • -s <serialNumber>
    通过指定的序列号对指定的设备或模拟器执行一条命令,这是指定设备更通用的方式;

以下所有命令均默认只有一个设备,若设备有多个,则应加-d、-e、-s serialno。

设备管理命令

命令 功能
adb get-state 判断设备状态
adb devices 显示连接到计算机的设备
adb get-serialno 获取设备的序列号
adb reboot 重启设备
adb reboot bootloader 重启设备进入fastboot模式
adb reboot recovery 重启设备进入recovery模式
adb kill-server 终止adb服务进程
adb start-server 重启 adb 服务进程
adb root 以 root 权限重启 adb 服务
adb connect ip[:port] 远程连接设备,要求此时目标设备监听TCP/IP连接,默认端口为5555
adb tcpip 5555 设备监听TCP/IP连接,端口为5555
adb disconnect ip[:port] 断开连接

获取设备信息命令

命令 功能
adb shell cat /sys/class/net/wlan0/address 获取 wifi mac 地址
adb shell cat /proc/cpuinfo 获取 cpu 信息
adb shell cat /system/build.prop 获取设备编译属性(手机属性和手机配置信息)
adb shell cat /data/misc/wifi/*.conf 获取 wifi 配置信息

管理设备APP命令

命令 功能
adb install [-r|-s] apkfile 安装 apk 文件
adb uninstall [-k] packagename 卸载 app
adb shell top [-m number] 查看内存占用情况
adb shell ps 查看进程列表
adb shell kill pid 杀死一个进程
adb shell ps –x pid 查看指定进程的状态
adb shell service list 查看后台 services 信息
abd shell pm list package 查看已经安装了的apk包名

文件操作命令

命令 功能
adb shell ls mnt 查看所有设备存储设备名
adb remount 将 system 分区重新挂载为可读写分区
adb push local remote 从本地复制文件到设备
adb pull remote local 从设备复制文件到本地
adb shell ls 列出目录下的文件和文件夹
adb shell cd folder 进入文件夹
adb shell rm [-r] path/filename 删除文件(夹)
adb shell cat file 查看文件内容
adb shell mkdir path/foldername 新建文件夹

其他命令

命令 功能
adb shell input text content 发送文本内容
adb shell input keyevent keycode 发送键盘事件
adb shell wm size 获取设备分辨率
adb shell getprop key 获取设备参数信息
adb shell setprop key value 设置设备参数信息
adb shell screencap –p 手机截图
adb shell screenrecord [options] 手机录像

不建议使用这些命令。具体参数请使用help。

总结

adb命令有很多,不需要死记,多用用就好。

猜你喜欢

转载自blog.csdn.net/Hey___Man/article/details/80860967