Android 抓取 ANR 日志终极办法

原文连接:技术小黑屋-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/android.frameworks.cameraservice.service@2.0::ICameraService_default.txt
  inflating: lshal-debug/android.frameworks.displayservice@1.0::IDisplayService_default.txt
  inflating: lshal-debug/android.frameworks.schedulerservice@1.0::ISchedulingPolicyService_default.txt
  inflating: lshal-debug/android.frameworks.sensorservice@1.0::ISensorManager_default.txt
  inflating: lshal-debug/android.frameworks.stats@1.0::IStats_default.txt
  inflating: lshal-debug/android.hardware.atrace@1.0::IAtraceDevice_default.txt
  inflating: lshal-debug/android.hardware.audio.effect@5.0::IEffectsFactory_default.txt
  inflating: lshal-debug/android.hardware.audio@5.0::IDevicesFactory_default.txt
  inflating: lshal-debug/android.hardware.biometrics.fingerprint@2.1::IBiometricsFingerprint_default.txt
  inflating: lshal-debug/android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory_default.txt
  inflating: lshal-debug/android.hardware.bluetooth@1.0::IBluetoothHci_default.txt
  inflating: lshal-debug/android.hardware.boot@1.0::IBootControl_default.txt
  inflating: lshal-debug/android.hardware.camera.provider@2.4::ICameraProvider_legacy_0.txt
  inflating: lshal-debug/android.hardware.cas@1.0::IMediaCasService_default.txt
  inflating: lshal-debug/android.hardware.cas@1.1::IMediaCasService_default.txt
  inflating: lshal-debug/android.hardware.configstore@1.0::ISurfaceFlingerConfigs_default.txt
  inflating: lshal-debug/android.hardware.configstore@1.1::ISurfaceFlingerConfigs_default.txt
  inflating: lshal-debug/android.hardware.contexthub@1.0::IContexthub_default.txt
  inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_default.txt
  inflating: lshal-debug/android.hardware.drm@1.0::ICryptoFactory_widevine.txt
  inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_default.txt
  inflating: lshal-debug/android.hardware.drm@1.0::IDrmFactory_widevine.txt
  inflating: lshal-debug/android.hardware.drm@1.1::ICryptoFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.drm@1.1::ICryptoFactory_widevine.txt
  inflating: lshal-debug/android.hardware.drm@1.1::IDrmFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.drm@1.1::IDrmFactory_widevine.txt
  inflating: lshal-debug/android.hardware.drm@1.2::ICryptoFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.drm@1.2::IDrmFactory_clearkey.txt
  inflating: lshal-debug/android.hardware.gatekeeper@1.0::IGatekeeper_default.txt
  inflating: lshal-debug/android.hardware.gnss@1.0::IGnss_default.txt
  inflating: lshal-debug/android.hardware.graphics.composer@2.1::IComposer_default.txt
  inflating: lshal-debug/android.hardware.health@2.0::IHealth_backup.txt
  inflating: lshal-debug/android.hardware.health@2.0::IHealth_default.txt
  inflating: lshal-debug/android.hardware.keymaster@3.0::IKeymasterDevice_default.txt
  inflating: lshal-debug/android.hardware.light@2.0::ILight_default.txt
  inflating: lshal-debug/android.hardware.media.c2@1.0::IComponentStore_software.txt
  inflating: lshal-debug/android.hardware.media.omx@1.0::IOmx_default.txt
  inflating: lshal-debug/android.hardware.media.omx@1.0::IOmxStore_default.txt
  inflating: lshal-debug/android.hardware.memtrack@1.0::IMemtrack_default.txt
  inflating: lshal-debug/android.hardware.nfc@1.0::INfc_default.txt
  inflating: lshal-debug/android.hardware.nfc@1.1::INfc_default.txt
  inflating: lshal-debug/android.hardware.power@1.0::IPower_default.txt
  inflating: lshal-debug/android.hardware.power@1.1::IPower_default.txt
  inflating: lshal-debug/android.hardware.radio.deprecated@1.0::IOemHook_slot1.txt
  inflating: lshal-debug/android.hardware.radio@1.0::IRadio_slot1.txt
  inflating: lshal-debug/android.hardware.radio@1.0::ISap_slot1.txt
  inflating: lshal-debug/android.hardware.radio@1.1::IRadio_slot1.txt
  inflating: lshal-debug/android.hardware.radio@1.1::ISap_slot1.txt
  inflating: lshal-debug/android.hardware.sensors@1.0::ISensors_default.txt
  inflating: lshal-debug/android.hardware.soundtrigger@2.0::ISoundTriggerHw_default.txt
  inflating: lshal-debug/android.hardware.soundtrigger@2.1::ISoundTriggerHw_default.txt
  inflating: lshal-debug/android.hardware.soundtrigger@2.2::ISoundTriggerHw_default.txt
  inflating: lshal-debug/android.hardware.thermal@1.0::IThermal_default.txt
  inflating: lshal-debug/android.hardware.thermal@2.0::IThermal_default.txt
  inflating: lshal-debug/android.hardware.usb@1.0::IUsb_default.txt
  inflating: lshal-debug/android.hardware.usb@1.1::IUsb_default.txt
  inflating: lshal-debug/android.hardware.vr@1.0::IVr_default.txt
  inflating: lshal-debug/android.hardware.wifi.supplicant@1.0::ISupplicant_default.txt
  inflating: lshal-debug/android.hardware.wifi.supplicant@1.1::ISupplicant_default.txt
  inflating: lshal-debug/android.hardware.wifi.supplicant@1.2::ISupplicant_default.txt
  inflating: lshal-debug/android.hardware.wifi@1.3::IWifi_default.txt
  inflating: lshal-debug/android.hidl.allocator@1.0::IAllocator_ashmem.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_AtCmdFwdService.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_ashmem.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_backup.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_clearkey.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_legacy_0.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_slot1.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_software.txt
  inflating: lshal-debug/android.hidl.base@1.0::IBase_widevine.txt
  inflating: lshal-debug/android.hidl.token@1.0::ITokenManager_default.txt
  inflating: lshal-debug/android.system.net.netd@1.0::INetd_default.txt
  inflating: lshal-debug/android.system.net.netd@1.1::INetd_default.txt
  inflating: lshal-debug/android.system.wifi.keystore@1.0::IKeystore_default.txt
  inflating: lshal-debug/vendor.qti.atcmdfwd@1.0::IAtCmdFwd_AtCmdFwdService.txt
  inflating: lshal-debug/vendor.qti.qcril.am@1.0::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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 210,914评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 89,935评论 2 383
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,531评论 0 345
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,309评论 1 282
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,381评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,730评论 1 289
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,882评论 3 404
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,643评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,095评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,448评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,566评论 1 339
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,253评论 4 328
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,829评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,715评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,945评论 1 264
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,248评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,440评论 2 348

推荐阅读更多精彩内容