擷取及讀取錯誤報告
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
錯誤報告包含裝置記錄、堆疊追蹤和其他診斷資訊,可協助找出並修正應用程式中的錯誤。如要從裝置擷取錯誤報告,您可以使用裝置的「取得錯誤報告」開發人員選項、Android Emulator 選單,或者開發機器的 adb bugreport
指令。
圖 1 裝置上的開發人員選項。
如要擷取錯誤報告,您必須先在裝置上啟用開發人員選項,才能使用「取得錯誤報告」選項。
擷取裝置的錯誤報告
圖 2. 錯誤報告已備妥。
如要直接從裝置擷取錯誤報告,請按照下列步驟操作:
- 啟用開發人員選項。
- 在「Developer options」中,輕觸「Take bug report」。
- 選取想要的錯誤報告類型,然後輕觸「Report」。
稍後您會收到錯誤報告已備妥的通知,如圖 2 所示。
- 如要分享錯誤報告,請輕觸通知。
透過 Android Emulator 擷取錯誤報告
在 Android Emulator 中,您可以使用擴充控制項中的回報錯誤功能:
- 按一下 Emulator 面板中的「More」圖示
。
在「Extended controls」視窗中,選取「Bug Report」。
您可以在開啟的畫面中查看錯誤報告詳細資料,例如螢幕截圖、AVD 設定資訊和錯誤報告記錄。此外,也可以輸入含有重現步驟的訊息,一併儲存在報表中。
等待錯誤報告收集完成,然後按一下「Save Report」。
使用 ADB 擷取錯誤報告
如果僅連結一部裝置,可以使用 adb
取得錯誤報告,如下所示:
$ adb bugreport E:\Reports\MyBugReports
若您未指定錯誤報告的路徑,該報告會儲存在本機目錄中。
如果連結多部裝置,就必須使用 -s
選項指定裝置。接著執行下列 adb
指令,取得裝置序號並產生錯誤報告:
$ adb devices
List of devices attached
emulator-5554 device
8XV7N15C31003476 device
$ adb -s 8XV7N15C31003476 bugreport
儲存先前的錯誤報告
錯誤報告的預設儲存位置為 /bugreports
,您可以使用下列指令查看報告:
$ adb shell ls /bugreports/
bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS-dumpstate_log-yyy.txt
bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip
dumpstate-stats.txt
接下來可透過 adb pull
提取 ZIP 檔案:
$ adb pull /bugreports/bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip
檢查錯誤報告 ZIP 檔案
ZIP 檔案會預設命名為 bugreport-BUILD_ID-DATE.zip
,可包含多個檔案,但最重要的檔案是 bugreport-BUILD_ID-DATE.txt
。這個檔案即為錯誤報告,內含系統服務的診斷輸出內容 (dumpsys
)、錯誤記錄 (dumpstate
) 和系統訊息記錄 (logcat
)。系統訊息包括裝置擲回錯誤時的堆疊追蹤,以及所有使用 Log
類別的應用程式寫入的訊息。
ZIP 檔案包含 version.txt
中繼資料檔案,內含 Android 版本字母。當 systrace 啟用時,ZIP 檔案也會包含 systrace.txt
檔案。Systrace 工具可擷取並顯示應用程式作業程序和其他 Android 系統作業程序的執行時間,協助分析應用程式效能。
dumpstate
工具會將裝置檔案系統中的檔案複製到 FS
資料夾下的 ZIP 檔案,方便您參照。舉例來說,裝置中的 /dirA/dirB/fileC
檔案會在 ZIP 檔案內產生 FS/dirA/dirB/fileC
項目。
圖 3. 錯誤報告檔案結構。
詳情請參閱「讀取錯誤報告」。
取得使用者回報的資訊
當您本人使用應用程式時,擷取錯誤報告是很實用的做法,但對您的使用者而言,與您分享這類錯誤報告並不容易。如要向實際使用者接收內含堆疊追蹤的錯誤報告,請善用 Google Play 和 Firebase 的當機回報功能。
Google Play 管理中心
您可以在 Google Play 管理中心取得報告,針對從 Google Play 安裝您應用程式的使用者,查看他們回報的當機和應用程式無回應 (ANR) 錯誤資料。系統提供過去六個月內的資料。
如需更多資訊,請前往 Play 管理中心的說明中心,參閱「查看當機與應用程式無回應 (ANR) 錯誤的資料」一文。
Firebase 當機回報
Firebase Crashlytics 回報功能會針對應用程式中的錯誤建立詳細報告。各項錯誤會根據類似的堆疊追蹤區分成不同問題,並依照對使用者的影響嚴重性來分類。除了自動產生的報告外,您也可以記錄自訂事件,這些資訊有助於找出造成當機的過程。
只要在 build.gradle
檔案中新增 Firebase 依附元件,即可開始接收所有使用者的當機報告。詳情請參閱「Firebase Crashlytics」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Capture and read bug reports\n\nA bug report contains device logs, stack traces, and other diagnostic\ninformation to help you find and fix bugs in your app. To capture a bug\nreport from your device, use the **Take bug report** developer\noption on the device, the Android Emulator menu,\nor the `adb bugreport` command on your development machine. \n\n**Figure 1.** Developer options on a device.\n\nTo take a bug report, you must have\n[Developer options](/studio/debug/dev-options) enabled on your\ndevice to access the **Take bug report** option.\n\nCapture a bug report from a device\n----------------------------------\n\n**Figure 2.** The bug report is ready.\n\nTo get a bug report directly from your device, do the following:\n\n1. Enable[Developer\n Options](/studio/debug/dev-options).\n2. In **Developer options** , tap **Take bug report**.\n3. Select the type of bug report you want and tap **Report** .\n\n\n After a moment, you get a notification that the bug report is ready, as\n shown in figure 2.\n4. To share the bug report, tap the notification.\n\nCapture a bug report from the Android Emulator\n----------------------------------------------\n\nFrom the Android Emulator, you can use the **File a bug**\nfeature in the extended controls:\n\n1. Click **More** in the Emulator panel.\n2. In the **Extended controls** window, select **Bug report**.\n\n This opens a screen where you can see the bug report details, such as the\n screenshot, the AVD configuration info, and the bug report log. You can\n also type a message with reproduction steps to save with the report.\n3. Wait for the bug report to finish collecting, then click **Save Report**.\n\nCapture a bug report using adb\n------------------------------\n\nIf you have just one device connected, you can get a bug report using\n[`adb`](/studio/command-line/adb), as follows: \n\n```\n$ adb bugreport E:\\Reports\\MyBugReports\n```\n\nIf you don't specify a path for the bug report, it is saved to\nthe local directory.\n\nIf you have multiple devices connected, you must specify the device with the\n`-s` option. Run the following `adb` commands to\nget the device serial number and generate the bug report: \n\n```\n$ adb devices\nList of devices attached\nemulator-5554 device\n8XV7N15C31003476 device\n\n$ adb -s 8XV7N15C31003476 bugreport\n```\n\nSave an older bug report\n------------------------\n\nBy default, bug reports are saved at `/bugreports` and can be viewed using the\nfollowing command: \n\n```\n$ adb shell ls /bugreports/\nbugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS-dumpstate_log-yyy.txt\nbugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip\ndumpstate-stats.txt\n```\n\nYou can then pull the zip file via `adb pull`: \n\n```\n$ adb pull /bugreports/bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip\n```\n\nInspect the bug report zip file\n-------------------------------\n\nBy default, the zip file is called\n`bugreport-`\u003cvar translate=\"no\"\u003eBUILD_ID\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eDATE\u003c/var\u003e`.zip`. The zip file\ncan contain multiple files, but the most important file is\n`bugreport-`\u003cvar translate=\"no\"\u003eBUILD_ID\u003c/var\u003e`-`\u003cvar translate=\"no\"\u003eDATE\u003c/var\u003e`.txt`. This\nis the bug report, which contains\ndiagnostic output for system services (`dumpsys`), error logs (`dumpstate`),\nand system message logs (`logcat`). The system messages include stack traces\nwhen the device throws an error and messages written from all apps with the\n[`Log`](/reference/android/util/Log) class.\n\nThe zip file contains a `version.txt` metadata file that contains\nthe Android release letter. When systrace is enabled, the zip file also\ncontains a `systrace.txt` file. The\n[Systrace tool](/topic/performance/tracing/command-line)\nhelps analyze the performance\nof your app by capturing and displaying execution times of your\napp processes and other Android system processes.\n\nThe `dumpstate` tool copies files from the device's file system\ninto the zip file under the `FS` folder so you can reference them. For example,\na \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003e/dirA/dirB/fileC\u003c/code\u003e\u003c/var\u003e file in the device would generate an\n\u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003eFS/dirA/dirB/fileC\u003c/code\u003e\u003c/var\u003e entry in the zip file.\n\n\n**Figure 3.** The bug report file structure.\n\n\u003cbr /\u003e\n\nFor more information, see\n[Reading bug reports](https://source.android.com/source/read-bug-reports.html).\n\nGet reports from your users\n---------------------------\n\nCapturing bug reports is helpful as you're using the app\nyourself, but your end-users can't easily share these types of bug reports\nwith you. To get crash reports with stack traces from real-world users,\ntake advantage of the Google Play and Firebase crash reporting\nfeatures.\n\n### Google Play Console\n\nYou can get reports from the\n[Google Play Console](https://play.google.com/console/)\nto view data for crashes and application not\nresponding (ANR) errors from users who installed your app from Google Play.\nData is available from the previous six months.\n\nFor more information, see\n[View crashes and application not responding (ANR) errors](https://support.google.com/googleplay/android-developer/answer/6083203?ref_topic=7071935)\nin Play Console help.\n\n### Firebase crash reporting\n\nFirebase Crashlytics reporting creates detailed reports of the errors in your\napp. Errors are grouped into issues based on similar stack traces and\ntriaged by the severity of impact on your users. In addition to automatic\nreports, you can log custom events to help capture the steps leading to a crash.\n\nTo start receiving crash reports from any user, [add the\nFirebase dependencies](https://firebase.google.com/docs/crashlytics/get-started?platform=android)\nto your `build.gradle` file. For more information, see\n[Firebase Crashlytics](https://firebase.google.com/docs/crashlytics/)."]]