Android开发之ANR原因分析
生活随笔
收集整理的這篇文章主要介紹了
Android开发之ANR原因分析
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
第一步拿到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"命令執(zhí)行二進制事件日志
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執(zhí)行am_anr和ANR in命令方法:點擊查看官方(實際上這兩個命令就是類似與搜索這個文件中的關(guān)鍵字"am_anr"和"ANR in")
如果上面方法獲取不到,可以使用高版本手機獲取方式
adb bugreport(高版本手機獲取ANR日志方法,高版本中的anr日志和低版本anr目錄日志默認是一樣的都在data/anr下面)
獲取后解壓可得到anr日志在根目錄/FS/data/anr下面就是ANR對應的日志文件
Android Studio打開profile的方法
Google官方文檔:獲取ANR日志方法
Google官方文檔:通過profile工具排查內(nèi)存泄露
總結(jié)
以上是生活随笔為你收集整理的Android开发之ANR原因分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《永劫无间》x《卧龙:苍天陨落》双向联动
- 下一篇: 怎么创建自己的微信小程序