一、ADB 简介
adb工具即Android Debug Bridge(安卓调试桥) tools。它就是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互。
二、ADB 常用命令
我把日常工作常用的命令都列在了下面,大家掌握下面这些也足够应付工作上的基本需求了。其他命令请自行百度学习。
2.1、查看连接的设备
adb devices
2.2、进入设备终端
adb shell
2.3、将apk安装到设备上
*.apk代表:安装当前目录下所有的apk文件
adb install xxx.apk
2.4、执行shell命令
adb shell command
2.5、从电脑上发送文件到设备
adb push <本地路径> <远程路径>
2.6、从设备上发送文件到电脑
adb pull <远程路径> <本地路径>
2.7、查看帮助信息
adb help
2.8、查看设备日志
adb logcat
2.9、重启设备
adb reboot
2.10、查看所有安装apk的包
pm list packages
2.11、根据某个关键字查找包
pm list packages | grep tencent
2.12、查看包安装位置
pm list packages -f
2.13、查看当前的Activity
adb shell "dumpsys window | grep mCurrentFocus
三丶ADB 高级命令
3.1、进入某个界面
adb shell "am start com.android.launcher3/com.android.launcher3.Launcher"
3.2、清理 log
adb shell logcat -c
3.3、将log保存到本地
adb logcat > D:xxx.txt
3.4、查看设备的所有功能
adb shell pm list features
3.5、获取系统属性
adb shell getprop xxx
3.6、设置系统属性
adb shell setprop xxx
3.7、开启TP画线
adb shell settings put system show_touches 1 && adb shell settings put system pointer_location 1
3.8、模拟按键
模拟返回(back)事件
adb shell input keyevent 4
键值表在:frameworks/base/core/java/android/view/KeyEvent.java
3.9、发送 broadcast
广播模型:
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("com.jlink.service.invisible".equals(action)) { //1
if(intent.hasExtra("invisible")){
boolean show = intent.getBooleanExtra("invisible", true); //2
NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
if (show) {
if (mNavigationBarView != null) return;
createNavigationBar(result);
SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, true);
}else{
if (mNavigationBarView == null) return;
mNavigationBarController.removeNavigationBarView();
//mNavigationBarView = null;
SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, false);
}
}else{
Log.w("StatusBar","didn't contain navigation_bar_show key");
}
}
//add end
}
};
解析:
1处,com.jlink.service.invisible 表示广播的唯一 action
2处,invisible 表示广播通信中,intent携带过来的值。
ADB发送广播:
adb shell am broadcast -a com.jlink.service.invisible --ez invisible false
综上所述,这条命令就很好理解了。
com.jlink.service.invisible 表示 action
invisible false 表示设置 invisible 的值为false
3.10、获取root权限
adb shell root
3.11、重新挂载系统分区
前提:拥有root权限
adb shell remount;
3.12、查看硬件Camera分辨率信息
第一步: △如果不打开是识别不到 video9 的
打开 Camera
第二步:
adb root;adb remount;adb shell v4l2-ctl -d /dev/video9 --list-formats-ext
3.13、强制竖屏
setprop persist.sys.app.rotation land
3.14、查看user版本还是userdebug版本
adb shell getprop ro.build.type
3.15、修改屏幕分辨率和DPI
#查询
adb shell wm size
#修改为指定分辨率
adb shell wm size 1136x2480
#恢复为默认分辨率
adb shell wm size reset
#dpi查询命令
adb wm density
#修改dpi
adb wm density 480
#恢复为默认dpi
adb shell wm density reset
3.16、查看 apk的编译模式
adb shell dumpsys package 包名
3.17、修改APK的编译模式
adb shell cmd package compile -m speed-profile -f 包名
3.18、查看APK的安装路径
adb shell pm path
3.19、检测WIFI信号
wpa_cli -i wlan0 scan
wpa_cli -i wlan0 scan_results
如果不行就先su一下
关于背光
3.19、读取ADC电压
cat /sys/bus/iio/devices/iio:device0/in_voltage2_raw
3.20、查看上报键值
getevent
getevent -l
了解更多参考:https://blog.csdn.net/pwp032984/article/details/125442990
3.21、永不休眠
adb shell settings put system screen_off_timeout 2147483647
3.22、查看cpu 64位还是32位
adb shell getprop ro.product.cpu.abi
3.23、启动某个应用
adb shell am start -n 包名/包名.MainActivity
3.24、卸载某个应用
adb uninstall 包名.
3.25、查询WiFi地址
adb shell cat /sys/class/net/wlan0/address
3.26、获取手机经纬度
adb shell dumpsys location| findstr “Last Know Location”
3.27、抓网络包
adb shell tcpdump
更多命令:
https://blog.csdn.net/weixin_37787043/article/details/126130634
https://blog.csdn.net/qq_26522993/article/details/127730235
3.28、精准定位线程
adb shell ps | findstr suppo
3.29、杀掉线程
adb shell kill 4760
3.30、获取sn号
adb shell getprop ro.serialno
3.31、adb logcat怎么打印时间
adb logcat -v time > D:aa.txt
3.32、查看IP
adb shell ifconfig wlan0
3.33、adb截图命令
adb shell screencap /sdcard/screen.png
将截图导出到PC的D盘
adb pull /sdcard/screen.png D:/log
3.34、查看节点值
cat /sys/class/leds/lcd-backlight/brightness
3.35、修改节点值
echo 128 > sys/class/leds/lcd-backlight/brightness
3.36、模拟触摸
通过 tap可以模拟触摸事件,参数是<x, y>
adb shell input tap 500 1450
滑动
adb shell input swipe 100 500 100 1450 100
3.37、长按电源键
adb shell input keyevent --longpress KEYCODE_POWER
3.38、查看设备电量
adb shell dumpsys battery | grep "level:"
3.39、过滤运行时异常和DEBUG异常
adb logcat -s AndroidRuntime,DEBUG > crash.txt
3.40、展讯进入MTP模式
adb shell am start -n "com.android.settings/com.sprd.settings.SprdUsbSettings"
3.41、 查看App版本号
adb shell "dumpsys package 包名 | grep versionName
3.42
查看电池温度
cat /sys/class/power_supply/battery/temp
cat /sys/class/power_supply/battery/bottom_temp
3.43
查看某个应用的权限
dumpsys package com.industry.bluetoothdemo | grep permission
3.44
列出所有应用的包名
adb shell pm list packages -f
3.45
查看系统版本
adb shell getprop ro.build.version.release
3.46
设置屏幕亮度最大
adb shell settings put system screen_brightness 255
3.47
获取当前活动的Activity信息
dumpsys activity activities
3.48
查看指定包名的详细信息
dumpsys package 包名
3.49、网络ADB
如果不行可能有两个原因
- 让设备和电脑处于同一个局域网,打开开发者选项,开启usb调试和无线调试
- adb版本太旧
Windwos:
https://dl.google.com/android/repository/platform-tools-latest-windows.zip
Mac:
https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
Linux:
https://dl.google.com/android/repository/platform-tools-latest-linux.zip
adb connect 192.168.x.xxx:5555
3.50、ADB 获取当前触摸的是哪个屏幕
logcat | grep display
3.51、在Windows上重启ADB服务器
adb kill-server
adb start-server
3.52、ADB 怎么push文件夹下所有的so到指定目录
adb push "C:\Users\szhj0\Desktop\miguyuedu\lib\arm64-v8a\" /data/local/tmp/
adb shell
su
cp /data/local/tmp/*.so /system/lib64/
chmod 644 /system/lib64/*.so # 设置正确权限
exit
3.53、查看SDK版本
adb shell getprop ro.build.version.sdk
3.54、查看CPU使用率
adb shell dumpsys cpuinfo 查看一次
adb shell "watch -n 1 dumpsys cpuinfo" 实时查看
3.55、查看内存
显示系统整体内存使用情况,包括应用内存使用详情。
adb shell dumpsys meminfo
如果只想查看某个特定应用的内存使用情况:
adb shell dumpsys meminfo <package_name>
参数说明:
-m 10 显示前10个进程
-s 6 按内存使用率排序(RSS)
adb shell top -m 10 -s 6
四、其他
1、Android Studio 的ADB路径
SDK/platform-tools
2、常见问题
- 1、 remote couldn’t create file: Read-only file system**
报错意思:远程无法创建只读文件系统
分析原因:没有root 权限,所以无法对手机内存进行读取或修改
解决方式:adb root;adb remount;
https://editor.csdn.net/md/?articleId=124412201