第一步拿到anr日志文件(低版本手机获取ANR日志方法)
bogon:wyze-doorbell-wireless-android-14 xiayiye5$ adb shell 进入手机目录
HS8917QC:/ $ cd data/anr 进入anr目录
HS8917QC:/data/anr $ ls 查看anr日志列表文件
traces.txt traces.txt.bugreport
HS8917QC:/data/anr $ ls -l 查看anr最近的一次列表文件
total 6408
-rw-rw-rw- 1 system system 591360 2021-05-11 10:36 traces.txt
-rw-rw-rw- 1 root root 2679219 2021-05-11 10:24 traces.txt.bugreport
HS8917QC:/data/anr $ exit
bogon:wyze-doorbell-wireless-android-14 xiayiye5$ adb pull data/anr/traces.txt 将anr文件复制到当前项目目录
data/anr/traces.txt: 1 file pulled, 0 skipped. 22.3 MB/s (591360 bytes in 0.025s)
bogon:wyze-doorbell-wireless-android-14 xiayiye5$
完整版:通过grep “am_anr”命令执行二进制事件日志
bogon:wyzemercury xiayiye5$ adb shell
HS8917QC:/ $ cd data/anr
HS8917QC:/data/anr $ ls
traces.txt traces.txt.bugreport
HS8917QC:/data/anr $ exit
bogon:wyzemercury xiayiye5$ adb pull data/anr/traces.txt
data/anr/traces.txt: 1 file pulled, 0 skipped. 27.7 MB/s (622675 bytes in 0.021s)
bogon:wyzemercury xiayiye5$ adb bugreport
/data/user_de/0/com.android.shell/files/bugreports/bugreport-N2G47H-2021-05-12-17-37-42.zip: 1 file pulled, 0 skipped. 24.6 MB/s (7429672 bytes in 0.288s)
Bug report copied to /Users/xiayiye5/AndroidStudioProjects/wyzemercury/bugreport-N2G47H-2021-05-12-17-37-42.zip
bogon:wyzemercury xiayiye5$ grep "am_anr" ./bugreport-N2G47H-2021-05-12-17-37-42/bugreport-N2G47H-2021-05-12-17-37-42.txt
05-11 10:22:55.008 1184 1197 I am_anr : [0,24669,com.wyze.template,954777158,Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 51. Wait queue head age: 5508.9ms.)]
05-11 10:24:00.876 1184 1197 I am_anr : [0,30024,com.wyze.template,954777158,Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 28. Wait queue head age: 5506.2ms.)]
05-11 10:36:01.241 1184 1197 I am_anr : [0,965,com.wyze.template,954777158,Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 19. Wait queue head age: 5620.3ms.)]
05-11 13:10:10.481 1184 1197 I am_anr : [0,5442,com.alpha.lagouapk,955825732,Broadcast of Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }]
05-11 13:56:15.171 1184 1197 I am_anr : [0,32409,cn.xiayiye5.xiayiye5library,954777414,Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)]
05-11 14:04:58.100 1184 1197 I am_anr : [0,19473,cn.xiayiye5.xiayiye5library,954777414,Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)]
05-11 14:41:40.823 1184 1197 I am_anr : [0,29853,cn.xiayiye5.xiayiye5library,954777414,Input dispatching timed out (Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.)]
05-12 15:42:48.533 1184 1197 I am_anr : [0,1872,com.wyze.template,952680006,Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 6. Wait queue head age: 5509.7ms.)]
Google官方grep执行am_anr和ANR in命令方法:
点击查看官方
(实际上这两个命令就是类似与搜索这个文件中的关键字”am_anr”和”ANR in”)
如果上面方法获取不到,可以使用高版本手机获取方式
adb bugreport(高版本手机获取ANR日志方法,高版本中的anr日志和低版本anr目录日志默认是一样的都在data/anr下面)
获取后解压可得到anr日志在根目录/FS/data/anr下面就是ANR对应的日志文件
Android Studio打开profile的方法
定位ANR错误代码行数犯法如下:(此方法仅限于未开启混淆的项目apk的ANR日志)
Google官方文档:
获取ANR日志方法
Google官方文档:
通过profile工具排查内存泄露
版权声明:本文为xiayiye5原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。