使用ADB查看安卓调试日志

生活很简单 复杂的是人 / 2024-06-08 / 原文

使用ADB查看安卓调试日志

安装ADB工具

官网下载地址:http://adbdownload.com/

根据自己的操作系统选择下载对应的安装包,本文以Windows为例

连接安卓设备

将设备(如手机/平板)的USB调试打开, 不同设备和不同版本的开启方式不同,根据实际情况处理.

USB调试打开之后, 将设备(如手机/平板)等通过数据线连接到电脑上, 然后打开cmd工具,执行以下命令

PS D:\Software\AndroidKiller_v1.3.1\bin\adb> .\adb.exe devices
List of devices attached

稍等几秒钟, 安卓设备将弹出提示:"是否允许USB调试", 点击允许即可

再次执行devices​命令, 就可以从列表中看到设备了

PS D:\Software\AndroidKiller_v1.3.1\bin\adb> .\adb.exe devices
List of devices attached
88Y5T19A17001949        device

查看设备日志

通过adb -s [device] logcat​命令, 可以看到设备的系统日志信息

PS D:\Software\AndroidKiller_v1.3.1\bin\adb> .\adb.exe -s 88Y5T19A17001949 logcat
--------- beginning of crash
05-27 20:48:46.431   434   434 F libc    : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x14 in tid 434 (init), pid 434 (init)
05-27 20:48:46.432   573   573 F libc    : failed to exec crash_dump helper: No such file or directory
05-27 20:48:46.432   434   434 F libc    : crash_dump helper failed to exec, or was killed

可以直接进入设备, 再执行logcat​命令.

PS D:\Software\AndroidKiller_v1.3.1\bin\adb> .\adb.exe -s 88Y5T19A17001949 shell
HWTAS:/ $ logcat | grep conn
logcat | grep conn
06-07 13:53:54.220  2544  3032 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:2040 android.content.ContextWrapper.bindService:810 ohos.abilityshell.support.O00000O.O000000:770 ohos.abilityshell.support.O00000O.connectAbility:604 ohos.abilityshell.support.O00000o.O000000:164
06-07 13:53:57.451 13492 13504 I HwActivityThreadImpl: before connect app.socketName:bee8ebf6-0074-4256-b4ae-22e957e46792
06-07 13:53:57.464 13492 13504 I HwActivityThreadImpl: connectContinuePreload end mPreloadStatus 3
06-07 13:53:57.614 13492 13594 D BufferPoolManager: # of cleaned connections: 0

直接进入设备shell后再使用logcat​的好处是, windows不支持的常见linux命令, 在shell里面可以执行, 例如grep

更多logcat的用法,参考 https://www.jianshu.com/p/5eed217327f5