飞道的博客

Android 抓取 ANR 日志终极办法

335人阅读  评论(0)

在 Android 开发中,有时会遇到 ANR,一旦出现 ANR 我们就需要拿到对应的trace 文件来分析并解决。本文将介绍两种获取 ANR 的方法。

第一种

直接查看/data/anr/traces.txt的内容,如下

adb shell cat  /data/anr/traces.txt

或者类似使用拷贝到电脑上查看,比如


   
  1. adb shell cp /data/anr/traces.txt /sdcard
  2. adb pull /sdcard/traces.txt ./

但是这种方法在某些手机上由于权限原因,无法进行,就需要了使用下面的方法了。

第二种

这种方法就是进行adb bugreport,没有权限限制问题。具体步骤是

生成 bugreport 文件


   
  1. adb bugreport
  2. /data/user_de/0/com.android.shell/files/bugreports/bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-30-21.zip: 1 file pulled, 0 skipped. 30.6 MB/s (3897489 bytes in 0.121s)
  3. Bug report copied to /private/tmp/bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-30-21.zip

进行解压文件


   
  1. unzip bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.zip
  2. Archive: bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.zip
  3. inflating: version.txt
  4. inflating: proto/SurfaceFlinger_CRITICAL.proto
  5. inflating: proto/activity_CRITICAL.proto
  6. inflating: proto/window_CRITICAL.proto
  7. inflating: FS/data/anr/anr_2021-01-12-14-59-10-559
  8. inflating: FS/data/misc/recovery/last_log
  9. inflating: FS/data/misc/recovery/last_kmsg
  10. inflating: FS/data/misc/recovery/ro.build.fingerprint
  11. inflating: FS/data/misc/recovery/proc/version
  12. inflating: FS/data/misc/update_engine_log/update_engine.19700914-172433
  13. inflating: FS/proc/1/mountinfo
  14. inflating: FS/proc/642/mountinfo
  15. inflating: FS/proc/643/mountinfo
  16. inflating: FS/proc/934/mountinfo
  17. inflating: FS/proc/2592/mountinfo
  18. inflating: FS/proc/2619/mountinfo
  19. inflating: FS/proc/2882/mountinfo
  20. inflating: FS/proc/3011/mountinfo
  21. inflating: FS/proc/3031/mountinfo
  22. inflating: FS/proc/3053/mountinfo
  23. inflating: FS/proc/3198/mountinfo
  24. inflating: FS/proc/3255/mountinfo
  25. inflating: FS/proc/3409/mountinfo
  26. inflating: FS/proc/3476/mountinfo
  27. inflating: FS/proc/3584/mountinfo
  28. inflating: FS/proc/3605/mountinfo
  29. inflating: FS/proc/3637/mountinfo
  30. inflating: FS/proc/3664/mountinfo
  31. inflating: FS/proc/3673/mountinfo
  32. inflating: FS/proc/3706/mountinfo
  33. inflating: FS/proc/3732/mountinfo
  34. inflating: FS/proc/3782/mountinfo
  35. inflating: FS/proc/3802/mountinfo
  36. inflating: FS/proc/3832/mountinfo
  37. inflating: FS/proc/3906/mountinfo
  38. inflating: FS/proc/3930/mountinfo
  39. inflating: FS/proc/4582/mountinfo
  40. inflating: FS/proc/5746/mountinfo
  41. inflating: FS/proc/6563/mountinfo
  42. inflating: FS/proc/7454/mountinfo
  43. inflating: FS/proc/7717/mountinfo
  44. inflating: FS/proc/8349/mountinfo
  45. inflating: FS/proc/8367/mountinfo
  46. inflating: FS/proc/8396/mountinfo
  47. inflating: FS/proc/8748/mountinfo
  48. inflating: FS/proc/8838/mountinfo
  49. inflating: FS/proc/8862/mountinfo
  50. inflating: FS/proc/8896/mountinfo
  51. inflating: FS/proc/8941/mountinfo
  52. inflating: FS/proc/10157/mountinfo
  53. inflating: FS/proc/10412/mountinfo
  54. inflating: FS/proc/26397/mountinfo
  55. inflating: FS/proc/26468/mountinfo
  56. inflating: FS/proc/27133/mountinfo
  57. inflating: FS/proc/27518/mountinfo
  58. inflating: FS/proc/29094/mountinfo
  59. inflating: FS/proc/29279/mountinfo
  60. inflating: FS/proc/29701/mountinfo
  61. inflating: FS/proc/31908/mountinfo
  62. inflating: lshal-debug/android.frameworks.cameraservice.service@2.0::ICameraService_default.txt
  63. inflating: lshal-debug/android.frameworks.displayservice@1.0::IDisplayService_default.txt
  64. inflating: lshal-debug/android.frameworks.schedulerservice@1.0::ISchedulingPolicyService_default.txt
  65. inflating: lshal-debug/android.frameworks.sensorservice@1.0::ISensorManager_default.txt
  66. inflating: lshal-debug/android.frameworks.stats@1.0::IStats_default.txt
  67. inflating: lshal-debug/android.hardware.atrace@1.0::IAtraceDevice_default.txt
  68. inflating: lshal-debug/android.hardware.audio.effect@5.0::IEffectsFactory_default.txt
  69. inflating: lshal-debug/android.hardware.audio@5.0::IDevicesFactory_default.txt
  70. inflating: lshal-debug/android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint_default.txt
  71. inflating: lshal-debug/android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory_default.txt
  72. inflating: lshal-debug/android.hardware.bluetooth@1.0::IBluetoothHci_default.txt
  73. inflating: lshal-debug/android.hardware.boot@1.0::IBootControl_default.txt
  74. inflating: lshal-debug/android.hardware.camera.provider@2.4::ICameraProvider_legacy_0.txt
  75. inflating: lshal-debug/android.hardware.cas@1.0::IMediaCasService_default.txt
  76. inflating: lshal-debug/android.hardware.cas@1.1::IMediaCasService_default.txt
  77. inflating: lshal-debug/android.hardware.configstore@1.0::ISurfaceFlingerConfigs_default.txt
  78. inflating: lshal-debug/android.hardware.configstore@1.1::ISurfaceFlingerConfigs_default.txt
  79. inflating: lshal-debug/android.hardware.contexthub@1.0::IContexthub_default.txt
  80. inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_clearkey.txt
  81. inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_default.txt
  82. inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_widevine.txt
  83. inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_clearkey.txt
  84. inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_default.txt
  85. inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_widevine.txt
  86. inflating: lshal-debug/android.hardware.drm@1.1::ICryptoFactory_clearkey.txt
  87. inflating: lshal-debug/android.hardware.drm@1.1::ICryptoFactory_widevine.txt
  88. inflating: lshal-debug/android.hardware.drm@1.1::IDrmFactory_clearkey.txt
  89. inflating: lshal-debug/android.hardware.drm@1.1::IDrmFactory_widevine.txt
  90. inflating: lshal-debug/android.hardware.drm@1.2::ICryptoFactory_clearkey.txt
  91. inflating: lshal-debug/android.hardware.drm@1.2::IDrmFactory_clearkey.txt
  92. inflating: lshal-debug/android.hardware.gatekeeper@1.0::IGatekeeper_default.txt
  93. inflating: lshal-debug/android.hardware.gnss@1.0::IGnss_default.txt
  94. inflating: lshal-debug/android.hardware.graphics.composer@2.1::IComposer_default.txt
  95. inflating: lshal-debug/android.hardware.health@2.0::IHealth_backup.txt
  96. inflating: lshal-debug/android.hardware.health@2.0::IHealth_default.txt
  97. inflating: lshal-debug/android.hardware.keymaster@3.0::IKeymasterDevice_default.txt
  98. inflating: lshal-debug/android.hardware.light@2.0::ILight_default.txt
  99. inflating: lshal-debug/android.hardware.media.c2@1.0::IComponentStore_software.txt
  100. inflating: lshal-debug/android.hardware.media.omx@1.0::IOmx_default.txt
  101. inflating: lshal-debug/android.hardware.media.omx@1.0::IOmxStore_default.txt
  102. inflating: lshal-debug/android.hardware.memtrack@1.0::IMemtrack_default.txt
  103. inflating: lshal-debug/android.hardware.nfc@1.0::INfc_default.txt
  104. inflating: lshal-debug/android.hardware.nfc@1.1::INfc_default.txt
  105. inflating: lshal-debug/android.hardware.power@1.0::IPower_default.txt
  106. inflating: lshal-debug/android.hardware.power@1.1::IPower_default.txt
  107. inflating: lshal-debug/android.hardware.radio.deprecated@1.0::IOemHook_slot1.txt
  108. inflating: lshal-debug/android.hardware.radio@1.0::IRadio_slot1.txt
  109. inflating: lshal-debug/android.hardware.radio@1.0::ISap_slot1.txt
  110. inflating: lshal-debug/android.hardware.radio@1.1::IRadio_slot1.txt
  111. inflating: lshal-debug/android.hardware.radio@1.1::ISap_slot1.txt
  112. inflating: lshal-debug/android.hardware.sensors@1.0::ISensors_default.txt
  113. inflating: lshal-debug/android.hardware.soundtrigger@2.0::ISoundTriggerHw_default.txt
  114. inflating: lshal-debug/android.hardware.soundtrigger@2.1::ISoundTriggerHw_default.txt
  115. inflating: lshal-debug/android.hardware.soundtrigger@2.2::ISoundTriggerHw_default.txt
  116. inflating: lshal-debug/android.hardware.thermal@1.0::IThermal_default.txt
  117. inflating: lshal-debug/android.hardware.thermal@2.0::IThermal_default.txt
  118. inflating: lshal-debug/android.hardware.usb@1.0::IUsb_default.txt
  119. inflating: lshal-debug/android.hardware.usb@1.1::IUsb_default.txt
  120. inflating: lshal-debug/android.hardware.vr@1.0::IVr_default.txt
  121. inflating: lshal-debug/android.hardware.wifi.supplicant@1.0::ISupplicant_default.txt
  122. inflating: lshal-debug/android.hardware.wifi.supplicant@1.1::ISupplicant_default.txt
  123. inflating: lshal-debug/android.hardware.wifi.supplicant@1.2::ISupplicant_default.txt
  124. inflating: lshal-debug/android.hardware.wifi@1.3::IWifi_default.txt
  125. inflating: lshal-debug/android.hidl.allocator@1.0::IAllocator_ashmem.txt
  126. inflating: lshal-debug/android.hidl.base@1.0::IBase_AtCmdFwdService.txt
  127. inflating: lshal-debug/android.hidl.base@1.0::IBase_ashmem.txt
  128. inflating: lshal-debug/android.hidl.base@1.0::IBase_backup.txt
  129. inflating: lshal-debug/android.hidl.base@1.0::IBase_clearkey.txt
  130. inflating: lshal-debug/android.hidl.base@1.0::IBase_legacy_0.txt
  131. inflating: lshal-debug/android.hidl.base@1.0::IBase_slot1.txt
  132. inflating: lshal-debug/android.hidl.base@1.0::IBase_software.txt
  133. inflating: lshal-debug/android.hidl.base@1.0::IBase_widevine.txt
  134. inflating: lshal-debug/android.hidl.token@1.0::ITokenManager_default.txt
  135. inflating: lshal-debug/android.system.net.netd@1.0::INetd_default.txt
  136. inflating: lshal-debug/android.system.net.netd@1.1::INetd_default.txt
  137. inflating: lshal-debug/android.system.wifi.keystore@1.0::IKeystore_default.txt
  138. inflating: lshal-debug/vendor.qti.atcmdfwd@1.0::IAtCmdFwd_AtCmdFwdService.txt
  139. inflating: lshal-debug/vendor.qti.qcril.am@1.0::IQcRilAudio_default.txt
  140. inflating: dumpstate_board.txt
  141. inflating: proto/activity.proto
  142. inflating: proto/incident.proto
  143. inflating: proto/stats.proto
  144. inflating: bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.txt
  145. inflating: main_entry.txt
  146. inflating: dumpstate_log.txt

查看 ANR stacktrace 文件

文件路径通常为FS/data/anr,具体可以根据日期来确定哪一个文件。

cat FS/data/anr/anr_2021-01-12-14-59-10-559

转载:https://blog.csdn.net/x2L5gX/article/details/114528181
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场