一、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
四、其他
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