Android 抓取 ANR 日志终极办法

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

第一种

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

adb shell cat  /data/anr/traces.txt

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

adb shell cp /data/anr/traces.txt /sdcard

adb pull /sdcard/traces.txt ./

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

第二种

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

生成 bugreport 文件

adb bugreport

/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)

Bug report copied to /private/tmp/bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-30-21.zip

进行解压文件

unzip bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.zip

Archive:  bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.zip

  inflating: version.txt

  inflating: proto/SurfaceFlinger_CRITICAL.proto

  inflating: proto/activity_CRITICAL.proto

  inflating: proto/window_CRITICAL.proto

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

  inflating: FS/data/misc/recovery/last_log

  inflating: FS/data/misc/recovery/last_kmsg

  inflating: FS/data/misc/recovery/ro.build.fingerprint

  inflating: FS/data/misc/recovery/proc/version

  inflating: FS/data/misc/update_engine_log/update_engine.19700914-172433

  inflating: FS/proc/1/mountinfo

  inflating: FS/proc/642/mountinfo

  inflating: FS/proc/643/mountinfo

  inflating: FS/proc/934/mountinfo

  inflating: FS/proc/2592/mountinfo

  inflating: FS/proc/2619/mountinfo

  inflating: FS/proc/2882/mountinfo

  inflating: FS/proc/3011/mountinfo

  inflating: FS/proc/3031/mountinfo

  inflating: FS/proc/3053/mountinfo

  inflating: FS/proc/3198/mountinfo

  inflating: FS/proc/3255/mountinfo

  inflating: FS/proc/3409/mountinfo

  inflating: FS/proc/3476/mountinfo

  inflating: FS/proc/3584/mountinfo

  inflating: FS/proc/3605/mountinfo

  inflating: FS/proc/3637/mountinfo

  inflating: FS/proc/3664/mountinfo

  inflating: FS/proc/3673/mountinfo

  inflating: FS/proc/3706/mountinfo

  inflating: FS/proc/3732/mountinfo

  inflating: FS/proc/3782/mountinfo

  inflating: FS/proc/3802/mountinfo

  inflating: FS/proc/3832/mountinfo

  inflating: FS/proc/3906/mountinfo

  inflating: FS/proc/3930/mountinfo

  inflating: FS/proc/4582/mountinfo

  inflating: FS/proc/5746/mountinfo

  inflating: FS/proc/6563/mountinfo

  inflating: FS/proc/7454/mountinfo

  inflating: FS/proc/7717/mountinfo

  inflating: FS/proc/8349/mountinfo

  inflating: FS/proc/8367/mountinfo

  inflating: FS/proc/8396/mountinfo

  inflating: FS/proc/8748/mountinfo

  inflating: FS/proc/8838/mountinfo

  inflating: FS/proc/8862/mountinfo

  inflating: FS/proc/8896/mountinfo

  inflating: FS/proc/8941/mountinfo

  inflating: FS/proc/10157/mountinfo

  inflating: FS/proc/10412/mountinfo

  inflating: FS/proc/26397/mountinfo

  inflating: FS/proc/26468/mountinfo

  inflating: FS/proc/27133/mountinfo

  inflating: FS/proc/27518/mountinfo

  inflating: FS/proc/29094/mountinfo

  inflating: FS/proc/29279/mountinfo

  inflating: FS/proc/29701/mountinfo

  inflating: FS/proc/31908/mountinfo

  inflating: lshal-debug/[email protected]::ICameraService_default.txt

  inflating: lshal-debug/[email protected]::IDisplayService_default.txt

  inflating: lshal-debug/[email protected]::ISchedulingPolicyService_default.txt

  inflating: lshal-debug/[email protected]::ISensorManager_default.txt

  inflating: lshal-debug/[email protected]::IStats_default.txt

  inflating: lshal-debug/[email protected]::IAtraceDevice_default.txt

  inflating: lshal-debug/[email protected]::IEffectsFactory_default.txt

  inflating: lshal-debug/[email protected]::IDevicesFactory_default.txt

  inflating: lshal-debug/[email protected]::IBiometricsFingerprint_default.txt

  inflating: lshal-debug/[email protected]::IBluetoothAudioProvidersFactory_default.txt

  inflating: lshal-debug/[email protected]::IBluetoothHci_default.txt

  inflating: lshal-debug/[email protected]::IBootControl_default.txt

  inflating: lshal-debug/[email protected]::ICameraProvider_legacy_0.txt

  inflating: lshal-debug/[email protected]::IMediaCasService_default.txt

  inflating: lshal-debug/[email protected]::IMediaCasService_default.txt

  inflating: lshal-debug/[email protected]::ISurfaceFlingerConfigs_default.txt

  inflating: lshal-debug/[email protected]::ISurfaceFlingerConfigs_default.txt

  inflating: lshal-debug/[email protected]::IContexthub_default.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_default.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_widevine.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_default.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_widevine.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_widevine.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_widevine.txt

  inflating: lshal-debug/[email protected]::ICryptoFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::IDrmFactory_clearkey.txt

  inflating: lshal-debug/[email protected]::IGatekeeper_default.txt

  inflating: lshal-debug/[email protected]::IGnss_default.txt

  inflating: lshal-debug/[email protected]::IComposer_default.txt

  inflating: lshal-debug/[email protected]::IHealth_backup.txt

  inflating: lshal-debug/[email protected]::IHealth_default.txt

  inflating: lshal-debug/[email protected]::IKeymasterDevice_default.txt

  inflating: lshal-debug/[email protected]::ILight_default.txt

  inflating: lshal-debug/[email protected]::IComponentStore_software.txt

  inflating: lshal-debug/[email protected]::IOmx_default.txt

  inflating: lshal-debug/[email protected]::IOmxStore_default.txt

  inflating: lshal-debug/[email protected]::IMemtrack_default.txt

  inflating: lshal-debug/[email protected]::INfc_default.txt

  inflating: lshal-debug/[email protected]::INfc_default.txt

  inflating: lshal-debug/[email protected]::IPower_default.txt

  inflating: lshal-debug/[email protected]::IPower_default.txt

  inflating: lshal-debug/[email protected]::IOemHook_slot1.txt

  inflating: lshal-debug/[email protected]::IRadio_slot1.txt

  inflating: lshal-debug/[email protected]::ISap_slot1.txt

  inflating: lshal-debug/[email protected]::IRadio_slot1.txt

  inflating: lshal-debug/[email protected]::ISap_slot1.txt

  inflating: lshal-debug/[email protected]::ISensors_default.txt

  inflating: lshal-debug/[email protected]::ISoundTriggerHw_default.txt

  inflating: lshal-debug/[email protected]::ISoundTriggerHw_default.txt

  inflating: lshal-debug/[email protected]::ISoundTriggerHw_default.txt

  inflating: lshal-debug/[email protected]::IThermal_default.txt

  inflating: lshal-debug/[email protected]::IThermal_default.txt

  inflating: lshal-debug/[email protected]::IUsb_default.txt

  inflating: lshal-debug/[email protected]::IUsb_default.txt

  inflating: lshal-debug/[email protected]::IVr_default.txt

  inflating: lshal-debug/[email protected]::ISupplicant_default.txt

  inflating: lshal-debug/[email protected]::ISupplicant_default.txt

  inflating: lshal-debug/[email protected]::ISupplicant_default.txt

  inflating: lshal-debug/[email protected]::IWifi_default.txt

  inflating: lshal-debug/[email protected]::IAllocator_ashmem.txt

  inflating: lshal-debug/[email protected]::IBase_AtCmdFwdService.txt

  inflating: lshal-debug/[email protected]::IBase_ashmem.txt

  inflating: lshal-debug/[email protected]::IBase_backup.txt

  inflating: lshal-debug/[email protected]::IBase_clearkey.txt

  inflating: lshal-debug/[email protected]::IBase_legacy_0.txt

  inflating: lshal-debug/[email protected]::IBase_slot1.txt

  inflating: lshal-debug/[email protected]::IBase_software.txt

  inflating: lshal-debug/[email protected]::IBase_widevine.txt

  inflating: lshal-debug/[email protected]::ITokenManager_default.txt

  inflating: lshal-debug/[email protected]::INetd_default.txt

  inflating: lshal-debug/[email protected]::INetd_default.txt

  inflating: lshal-debug/[email protected]::IKeystore_default.txt

  inflating: lshal-debug/[email protected]::IAtCmdFwd_AtCmdFwdService.txt

  inflating: lshal-debug/[email protected]::IQcRilAudio_default.txt

  inflating: dumpstate_board.txt

  inflating: proto/activity.proto

  inflating: proto/incident.proto

  inflating: proto/stats.proto

  inflating: bugreport-sailfish-QP1A.191005.007.A3-2021-01-12-15-32-54.txt

  inflating: main_entry.txt

  inflating: dumpstate_log.txt

查看 ANR stacktrace 文件

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

cat FS/data/anr/anr_2021-01-12-14-59-10-559
下载说明:
1、本站所有资源均从互联网上收集整理而来,仅供学习交流之用,因此不包含技术服务请大家谅解!
2、本站不提供任何实质性的付费和支付资源,所有需要积分下载的资源均为网站运营赞助费用或者线下劳务费用!
3、本站所有资源仅用于学习及研究使用,您必须在下载后的24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担!
4、本站站内提供的所有可下载资源,本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发),但本站不保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug!如有链接无法下载、失效或广告,请联系客服处理!
5、本站资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您的合法权益,请立即告知本站,本站将及时予与删除并致以最深的歉意!
6、如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
7、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务!
8、请您认真阅读上述内容,注册本站用户或下载本站资源即您同意上述内容!
原文链接:https://www.dandroid.cn/20775,转载请注明出处。
0

评论0

显示验证码
没有账号?注册  忘记密码?