ADB环境搭建及常用命令

安装adb环境步骤

1. 进入安卓官网:Android 开发者  |  Android Developers -> 搜索SDK Platform Tools,下载对应的版本

2. 解压下载的文件,接下来配置环境变量。

3. 右键我的电脑->属性->高级系统设置->环境变量->编辑系统变量的path->添加adb文件夹的路径

4. 此时打开终端(运行里面输入cmd),输入adb,出现adb相关信息就算安装成功

5. adb API地址:Android Debug Bridge | Android中文API

ADB命令大全

adb version

查看adb版本

adb connect 127.0.0.1:21503

连接逍遥模拟器

adb devices

设备/模拟器的连接状态

adb get-state

获取设备连接状态

adb shell pm list packages

查看手机上应用包名

adb install+(电脑上路径地址+软件名)

安装软件路径

adb uninstall + 已安装的应用包名

卸载已安装的应用

adb shell pm path <包名>

打印指定包名的路径

adb shell

进入手机

exit

退出手机

adb push 文件位置\文件名 /sdcard/

电脑上文件发送到手机设备上

adb pull /sdcard/文件名 d:/

将手机上的文件传送到我们的电脑上

adb shell getprop ro.build.version.release

查看手机系统版本信息

adb get-serialno

获取设备序列号

adb start-server

启动adb服务

adb kill-server

关闭adb服务

adb logcat

查看和跟踪系统日志

adb logcat -f /sdcard/test.txt

将日志输出到文件

adb  logcat -v time > 电脑路径/文件名

抓取日志导入电脑

adb logcat -c

清理已存在的日志

adb shell monkey -p 包名 --throttle 300  --monitor-native-crashes -v -v 10000 > 电脑端地址+文件名

产生时间序列的种子值:500 每次延迟1秒,忽略程序崩溃 、 忽略超时 、 监视本地程序崩溃 、 详细信息级别为2 , 产生 10000个事件 。(模拟用户的按键输入,触摸屏输入,手势输入等,看设备多长时间会出异常)

throttle 300  延迟

设置为300毫秒,原因是实际用户操作的最快300毫秒左右一个动作事件,所以此处一般设置为300毫秒。

-s

伪随机数生成器的seed值

ignore-crashes

忽略崩溃

gnore-timeouts

忽略超时

ignore-security-exceptions

忽略安全异常

kill-process-after-error

发生错误后直接杀掉进程

adb报告分析

  1. 搜索报告中的关键字“ANR”,看有无应用无响应的事件(Application Not Responding)
  2. 搜索报告中的关键字“crash”,看有无崩溃的事件
  3. 搜索报告中的关键字“exception”,看有无其他异常事件。(如果出现空指针, NullPointerException,需格外重视)
  4. 内存泄露问题搜索"GC"

adb shell top

查看手机进程信息

adb shell top | findstr 包名

查看单个程序pid

adb shell dumpsys window | findstr mCurrentFocus

获得当前应用的包名及activity

adb shell am start -W -n 包名/活动

冷启动

adb shell am force-stop 包名

冷启动停止

home键返回
adb shell input keyevent 3

热启动停止(模拟按键输入、输出)

先打开app后台运行
adb shell am start -W -n 包名/活动

热启动

adb shell ps

获得应用程序的pid(统计流量)

adb shell cat /proc/15320/net/dev

查看流量

adb shell dumpsys battery

查看温度,usb充电

adb shell dumpsys battery set status 1

查看温度,usb未充电,未成功

adb shell pm clear <包名>

清除软件缓存

adb reboot

重启手机

创建批处理文件

1. 新建text
2. 将需要执行的命令输入, 比如我们先截屏到手机,再把该截图拉到电脑里面
adb shell screencap -p /sdcard/2.png
adb pull /sdcard/2.png D:\Users
3. 另存为.bat批处理文件
4. 执行批处理文件直接双击执行就行

Monkey稳定性测试

  1. 先清空日志:adb logcat -c
  2. 抓日志:adb logcat *:W -v time > ./1.log
  3. Itest软件监控打开
  4. 执行monkey方法: adb shell monkey -p tv.danmaku.bili --throttle 1000 --monitor-native-crashes -v -v 100 > D:\Users\test.log

ADB常见操作

如何重启adb服务?

adb kill-server
adb start-server

app安装与卸载

adb -s <devicename> install <path-to-apk>
adb -s <devicename> install -r <path-to-apk>  #覆盖安装
adb -s <devicename> uninstall <packagename>

如何在电脑和手机之间传输数据?

adb push <电脑文件路径> <手机路径>
adb pull <手机路径> <电脑文件路径>

如何静默安装APP?

adb push <电脑文件路径> <手机路径>
adb shell pm install -f <手机路径>

如何启停app?

adb shell am start -W -S package/activity
adb shell am force-stop package

如何通过某个关键字查找已安装的包?

adb shell pm list package -f keyword
adb shell pm list package -3 keyword
adb shell pm list package -i keyword

如何截屏、录屏?

adb shell screencap <手机地址>
adb shell screenrecord <手机地址>

如何获取当前的CPU、内存状态?

adb shell dumpsys meminfo package
adb shell dumpsys cpuinfo | findstr package

其他补充:

查看设备第三方软件 ==adb shell pm list packages -3

包名如何查看 == adb shell pm list^_^mo''''''''M packages 返回的packages:后面的是包名


从模拟器复制文件到本地 ==== adb pull 模拟器文件路径 本地路径--实操:

例:adb pull /sdcard/Pictures/Screenshots/Screenshot_2020-09-08-14-51-13.png

第一步:先查看当前目录下面的所有文件夹,选择sdcard文件

第二步:进入sdcard文件并进行查看:cd sdcard找到pictures

第三步:进入pictures/screenshots 文件并查看所有文件列表:

最后一步:将模拟上的文件复制到我们的本地(前提将我们要复制的文件按照前面的步骤找出路径)


从本地复制文件到模拟器

adb push 本地文件路径 模拟器路径

例:adb push C:\Users\1\123.txt /sdcard/Pictures/Screenshots/fanmao123.txt

查看设备型号 === adb shell getprop ro.product.model

查看内存信息 === adb shell cat /proc/meminfo

查看cpu信息 ==== adb shell cat /proc/cpuinfo

查看模拟器IP地址 ======= adb shell ifconfig wlan0

查看模拟器MAC地址 ===== adb shell cat /sys/class/net/wlan0/address


统计流量 ============ adb shell ps 查看软件pid 

adb shell cat /proc/PID编号/net/dev 查看到流量记录文档

注意:

wlan0表示wifi流量

lo表示本地流量

receive表示接收数据流量

transmite表示发出数据流量


查看模拟器和指定服务器的网络连通性 === adb shell ping 域名/ip地址

ctrl + c 中断连接(如果你连接成功的情况下不断在连接,使用中断快捷键


monkey测试:

monkey测试在adb命令行工具中的一个指令,通过随机向手机发送设定数量的动作,可以测试软件的稳定性和健壮性。

>monkeytest.txt:即将我们执行的结果报告存档在默认路径下面的monkeytest.txt文档里

测试结果:

1.有Monkey finished关键字

2.搜索关键字 error crash ANR (程序未响应)


-p 包名 必写

没有-v 开始和结束的日志提醒

-v 提示所有和被测软件相关的日志信息

-v -v 提示所有被测软件和后台缓存相关的日志信息

-v -v -v 提示所有手机内日志信息

--throttle 数字[毫秒] 动作直接的延迟时间

--ignore-crashes 忽略崩溃


--ignore-timeouts 忽略超时

--pct-touch 点击动作

--pct-motion 滑动操作

--pct-trackball 点击加滑动

--pct-syskeys 系统按键

--pct-anyevent 任何事件

--pct-appswitch app切换


adb shell monkey -p com.youdao.calculator -v --throttle 500 --pct-anyevent 100 500

-p:后面加的是包名

-v:是显示文档详情的等级level0

--throttle 500 : 执行事件时的延迟时间 ,500毫秒

--pct-anyevent:执行的是任意事件


100 500 :100是执行的百分比,即百分之一百的事件执行成功,500是要求执行的500件事件

adb shell monkey -p com.youdao.calculator -p com.moji.mjweather --throttle 300 --pct-touch 80 --pct-anyevent 10 --pct-appswitch 10 500 >monkeyTest.txt


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值