美文网首页程序员Android知识Android技术知识
adb -Android Debug Bridge安卓调试桥(一

adb -Android Debug Bridge安卓调试桥(一

作者: Tester_Jingel | 来源:发表于2017-03-20 17:10 被阅读329次

一、安装与下载

由于Android sdk中有adb.exe我们配置好环境变量就可以使用啦!
配置软文链接处---》

二、adb 操作命令大全

  • 查看版本

adb version #查看adb工具当前的版本信息

  • 查看连接设备信息

adb devices #包含设备序列号,出现名称代表连接成功 -------注意打开USB调试


adb devices.png

三、安装/卸载apk应用

  • adb install 安装包路径+安装包全名包括扩展名


    adb install.png
  • adb uninstall 包名 (注意是包名不能加扩展名和数字)


    adb uninstall.png
  • adb shell pm clear <packagename> #清除应用数据与缓存

四、列出应用的包名

  • adb shell pm list packages #列出手机装的所有app的包名
  • adb shell pm list packages -s #列出系统应用的所有包名
  • adb shell pm list packages -3 #列出除了系统应用的第三方应用包名

五、查看日志

日志分析.png

(1)Android日志

  • 命令格式:[adb] logcat [<option>] ... [<filter-spec>] ...
    按级别过滤日志:
    Android 的日志分为如下几个优先级(priority):
    V —— Verbose(最低,输出得最多)
    D —— Debug
    I —— Info
    W —— Warning
    E —— Error
    F —— Fatal
    S —— Silent(最高,啥也不输出)
adb logcat *:W   #会将 Warning、Error、Fatal 和 Silent 日志输出。```
- 按 tag 和级别过滤日志

adb logcat ActivityManager:I MyApp:D *:S #表示输出 tag ActivityManager 的 Info 以上级别日志,输出 tag MyApp 的 Debug
以上级别日志,及其它 tag 的 Silent 级别日志(即屏蔽其它 tag 日志)。

- adb logcat -s Unity #过滤成tag为Unity的log日志
- adb logcat >test.log #保存log到本地文档



(2)内核日志
>- adb shell dmesg

输出示例:
<6>[ 2676.308152] ltr559_resume
<3>[ 2676.308166] dpm_run_callback(): i2c_device_pm_resume+0x0/0x28 returns -297937324
<3>[ 2676.308171] PM: Device 0-0023 failed to resume: error -297937324
<6>[ 2676.313940] psy->name:battery
<6>[ 2676.314576] status=3, percent=65
<6>[ 2676.314985] status=3, percent=65
<6>[ 2676.316534] xiexp debug alarm rtc_alarm_irq_enable:
<6>[ 2676.316535] PM: resume of devices complete after 290.078 msecs
<6>[ 2676.322395] mmc0: Starting deferred resume
<6>[ 2676.317828] Restarting tasks ... done.
<6>[ 2676.324816] PM: suspend exit 2017-03-20 08:31:22.049500289 UTC
<12>[ 2676.325990] healthd: battery l=65 v=3966 t=31.0 h=2 st=4 c=6 chg=
<6>[ 2676.405781] mmc0: Deferred resume completed
批注:[ 2676.308152]代表内核开始启动后的时间,单位为秒。


###补充:
>- 获取系统版本:adb shell getprop ro.build.version.release
- 获取系统api版本:adb shell getprop ro.build.version.sdk
- 获取包的版本和版本号:adb shell dumpsys package xxxx包名
- 获取当前运行的APP的包名和Activity :adb shell dumpsys window | findstr mCurrentFocus
- 获取手机的Android版本:adb shell getprop ro.build.version.release
- 查看activity:adb shell dumpsys activity activities 
- 查看APP的version code 和version name:adb shell dumpsys package xxx包名

1、
Home键:3
返回键:4
唤醒屏幕:adb shell input keyevent 224
休眠屏幕:adb shell input keyevent 223
滑动解锁:adb shell input swipe 300 1000 300 500
清除应用数据:adb shell pm clear 包名
获取应用的activity:adb shell dumpsys window | findstr mCurrentFocus
查看activity:adb shell dumpsys activity activities 
启动应用:adb shell am start -n activity数据
杀除进程:adb shell am force-stop 包名

2、获取设备ID:adb shell settings get secure android_id

3、截图保存到电脑:adb exec-out screencap -p > sc.png

4、录制视频:adb shell screenrecord /sdcard/filename.mp4
   发送电脑:adb pull /sdcard/filename.mp4
   视频尺寸:--size WIDTHxHEIGHT

5、重启手机:adb reboot
6、查看进程的启动时间:
首先获取activity:adb shell dumpsys window | findstr mCurrentFocus
adb shell am start -W  packagename/activityxxx
如果只关心某个应用自身启动耗时,参考TotalTime;
如果关心系统启动应用耗时,参考WaitTime;
如果关心应用有界面Activity启动耗时,参考ThisTime。

![adb.png](https://img.haomeiwen.com/i2539401/89deb97a6a7b75f9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

相关文章

网友评论

    本文标题:adb -Android Debug Bridge安卓调试桥(一

    本文链接:https://www.haomeiwen.com/subject/uegenttx.html