Android 抓取 ANR 日志終極辦法

原文連接:技術(shù)小黑屋-Android 抓取 ANR 日志終極辦法
在 Android 開(kāi)發(fā)中瞄桨,有時(shí)會(huì)遇到 ANR坯临,一旦出現(xiàn) ANR 我們就需要拿到對(duì)應(yīng)的trace 文件來(lái)分析并解決。本文將介紹兩種獲取 ANR 的方法捍壤。

第一種

直接查看/data/anr/traces.txt的內(nèi)容,如下

adb shell cat  /data/anr/traces.txt

或者類似使用拷貝到電腦上查看,比如

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

但是這種方法在某些手機(jī)上由于權(quán)限原因童太,無(wú)法進(jìn)行烫罩,就需要了使用下面的方法了洪己。

第二種

這種方法就是進(jìn)行adb bugreport,沒(méi)有權(quán)限限制問(wèn)題蠢棱。具體步驟是

生成 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


進(jìn)行解壓文件

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锌杀,具體可以根據(jù)日期來(lái)確定哪一個(gè)文件甩栈。

cat FS/data/anr/anr_2021-01-12-14-59-10-559
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市糕再,隨后出現(xiàn)的幾起案子量没,更是在濱河造成了極大的恐慌,老刑警劉巖亿鲜,帶你破解...
    沈念sama閱讀 207,248評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件允蜈,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡蒿柳,警方通過(guò)查閱死者的電腦和手機(jī)饶套,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,681評(píng)論 2 381
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)垒探,“玉大人妓蛮,你說(shuō)我怎么就攤上這事』穑” “怎么了蛤克?”我有些...
    開(kāi)封第一講書(shū)人閱讀 153,443評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)夷蚊。 經(jīng)常有香客問(wèn)我构挤,道長(zhǎng),這世上最難降的妖魔是什么惕鼓? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,475評(píng)論 1 279
  • 正文 為了忘掉前任筋现,我火速辦了婚禮,結(jié)果婚禮上箱歧,老公的妹妹穿的比我還像新娘矾飞。我一直安慰自己,他們只是感情好呀邢,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,458評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布洒沦。 她就那樣靜靜地躺著,像睡著了一般价淌。 火紅的嫁衣襯著肌膚如雪申眼。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,185評(píng)論 1 284
  • 那天输钩,我揣著相機(jī)與錄音豺型,去河邊找鬼。 笑死买乃,一個(gè)胖子當(dāng)著我的面吹牛姻氨,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播剪验,決...
    沈念sama閱讀 38,451評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼肴焊,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼前联!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起娶眷,我...
    開(kāi)封第一講書(shū)人閱讀 37,112評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤似嗤,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后届宠,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體烁落,經(jīng)...
    沈念sama閱讀 43,609評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,083評(píng)論 2 325
  • 正文 我和宋清朗相戀三年豌注,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了伤塌。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,163評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡轧铁,死狀恐怖每聪,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情齿风,我是刑警寧澤药薯,帶...
    沈念sama閱讀 33,803評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站救斑,受9級(jí)特大地震影響童本,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜脸候,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,357評(píng)論 3 307
  • 文/蒙蒙 一巾陕、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧纪他,春花似錦、人聲如沸晾匠。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,357評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)凉馆。三九已至薪寓,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間澜共,已是汗流浹背向叉。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,590評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留嗦董,地道東北人母谎。 一個(gè)月前我還...
    沈念sama閱讀 45,636評(píng)論 2 355
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像京革,于是被迫代替她去往敵國(guó)和親奇唤。 傳聞我的和親對(duì)象是個(gè)殘疾皇子幸斥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,925評(píng)論 2 344

推薦閱讀更多精彩內(nèi)容