adb安装
1、安装homebrew
# 官方下载
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# ruby下载
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装adb
brew cask install android-platform-tools
adb命令
1、adb常用命令
# 查看设备信息
adb devices //查看设备信息
adb devices -l //查看设备详细信息
adb shell dumpsys meminfo //查看设备内存
adb shell cat /proc/meminfo //查看设备存储空间
adb shell getprop ro.product.model //获取设备名称
adb shell getprop ro.build.version.release //获取设备系统版本号
adb shell getprop ro.serialno //获取设备SN码
adb push /yourpath /sdcard //将文件写入设备
# adb服务
adb start-server //启动adb的后台进程
adb stop-server //关闭adb的后台进程
adb tcpip xxx(地址) //脱离USB线的tcp连接方式
adb connect xxx:xxx //连接开启了TCP连接方式的设备
adb disconnect xxx:xxx //断开连接
# 安装、卸载apk
adb install 包名 //安装apk包
adb install -r 包名 //覆盖安装apk包
adb install -t 包名 //安装测试apk包
adb uninstall 包名 //卸载apk包
# 获取包名
adb shell pm list package cn. //获取包含cn.的包名
adb shell pm list packages //获取设备所有包名
adb shell pm list pakeages -3 //获取第三方apk包名
adb shell dumpsys activity top | awk -F " " '/TASK/ {print $2}' //获取当前运行apk包名
adb shell "dumpsys window w|grep \/|grep name=|sed 's/mSurface=Surface(name=//g'|sed 's/)//g'|sed 's/ //g'" //获取当前运行apk包名和activity
# 截图、录屏
adb shell screencap -p /sdcard/xxx.png //截图
adb pull /sdcard/1.png /path //将截图移至path
adb shell rm /sdcard/xxx.png //删除截图
adb shell screenrecord --time-limit xxx /sdcard/xxx.mp4 //录屏,xxx为录屏时间(单位:s)
adb pull /sdcard/1.mp4 /path //将录屏移至path
adb shell rm /sdcard/xxx.mp4 //删除录屏
# 操作设备
adb reboot //重启手机
adb shell am start -n xxxx/com.xxx.main.activity.MainActivity //启动应用
adb shell am force-stop cn.freshbuddy.xxxx //强制停止应用
adb shell pm clear cn.freshbuddy.xxxxx //清除数据
# 查看日志
adb logcat //查看日志,可填加到自定义路径文件
adb bugrepor //收集日志数据,耗电量,用于后续分析
adb logcat -v threadtime > desktop/log1.txt //导出crash log
2、monkey压力测试
# 上传两个jar包到手机sdcard根目录,jar包可以自己封装或自行下载
adb push framework.jar /sdcard
adb push monkey.jar /sdcard
# 执行monkey运行命令
adb shell CLASSPATH=/sdcard/monkey.jar:/sdcard/framework.jar exec app_process /system/bin tv.panda.test.monkey.Monkey -p xxx --uiautomatormix --running-minutes 1 -v -v >/Users/apple/Desktop/log.txt
* 命令参数含义
* tv.panda.test.monkey.Monkey //封装好的monkey入口类,不用修改
* xxx //app包名
* --uiautomatormix //遍历策略
* --running-minutes //运行时长,1就是1分钟,60就是60分钟
* >/Users/apple/Desktop/log.txt //导出log日志
* 分析日志
* 程序无响应的问题:在日志中搜索 “ANR”
* 崩溃问题:在日志中搜索 “Exception” (如果出现空指针, NullPointerException)
* 搜索"crash" 、"error"等