Android 常用的adb 命令

2,118 阅读2分钟

1.查看连接的设备 
adb devices

2.安装apk
adb install  apk的地址
adb install -r   允许覆盖安装
adb install -d  允许降级安装

3.卸载apk
adb uninstall  xxxx包名

4.清除应用数据与缓存
adb shell pm clear xxxx包名

5.查看adb 版本
adb version

6.启动adb
adb start-service

7.停止adb  
adb kill-service

8.以 root 权限运行 adb 
adb root

9.指定 adb server 的网络端口
adb -P start-server   默认是5037

10.查看所有应用
adb shell pm list packages

11.查看前台 Activity
adb shell dumpsys activity activities

12.启动应用/ 调起 Activity
adb shell am start -n xx包名/.xx启动的activity

例如: adb shell am start -n com.android.settings/.Setting 打开系统设置界面

13.抓取ANR日志
adb  shell ==》cd data/anr ==》ls  ==》adb pull /data/anr/anr_2019-12-16-10-05-18-637

14.查看设备屏幕分辨率
adb shell wm size

15.查看设备屏幕密度
adb shell wm density

16.查看设备 Mac 地址
adb shell cat /sys/class/net/wlan0/address

17.查看设备显示屏参数
adb shell dumpsys window displays

  1. 开启/关闭 WiFi
    adb root
    adb shell svc wifi enable
    adb shell svc wifi disable

19.将指定的文件从计算机上传到模拟器/设备
adb push  D:\Download\music.mp4   /sdcard/music/

20.从设备下载指定的文件到计算机
adb pull   /sdcard/music.mp4   D:\Download\music.mp4

21.查看文件内容如:data.txt
adb root 
adb shell
cat  data.txt

22.设备连着 WiFi,可以使用如下命令来查看局域网 IP
adb shell ifconfig wlan0

23.根据包名找到apk所在的位置

 adb shell pm path com.tence01.mm

  1. 获取settings指定属性值

adb shell settings get global disable_list

25.获取Android_ID

adb shell settings get secure android_id

26.通过命令打开或关闭屏幕指针位置

adb shell settings put system pointer_location 1

adb shell settings put system pointer_location 0

  1. 截屏

adb shell screencap /sdcard/1.png

28.返回键

adb shell input keyevent 4

29.输入密码,并回车

adb shell input text 87654321 && adb shell input keyevent 66

30.adb 命令开启布局边界

adb shell setprop debug.layout true

31.查看adb.exe所在位置

where adb