获取并阅读 bug 报告
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
bug 报告包含设备日志、堆栈轨迹和其他诊断信息,有助于您查找和修复应用中的 bug。若要从设备获取 bug 报告,请使用设备上的生成 bug 报告开发者选项、使用 Android 模拟器菜单或使用开发机器上的 adb bugreport
命令。
图 1. 设备上的开发者选项。
如需生成 bug 报告,您必须在设备上启用开发者选项,才能使用生成 bug 报告选项。
从设备上获取 bug 报告
图 2. bug 报告已准备就绪。
如需直接从您的设备获取 bug 报告,请执行以下操作:
- 启用开发者选项。
- 在开发者选项中,点按生成 bug 报告。
- 选择所需的 bug 报告类型,然后点按报告。
片刻之后,您便会收到 bug 报告已准备就绪的通知,如图 2 所示。
- 如需分享 bug 报告,请点按该通知。
从 Android 模拟器上获取 bug 报告
在 Android 模拟器中,您可以使用“Extended controls”窗口中的 File a bug 功能:
- 点击模拟器面板中的 More 图标
。
在 Extended controls 窗口中选择 Bug report。
此时系统会打开一个屏幕,您可以在其中查看 bug 报告详细信息,例如屏幕截图、AVD 配置信息和 bug 报告日志。您还可以输入一条包含重现步骤的消息,以便与报告一起保存。
等待 bug 报告完成收集,然后点击 Save Report。
使用 adb 获取 bug 报告
如果您只连接了 1 部设备,则可以使用 adb
获取 bug 报告,如下所示:
$ adb bugreport E:\Reports\MyBugReports
如果您未为 bug 报告指定路径,系统会将其保存到本地目录。
如果您连接了多部设备,则必须使用 -s
选项指定设备。运行以下 adb
命令可获取设备序列号并生成 bug 报告:
$ adb devices
List of devices attached
emulator-5554 device
8XV7N15C31003476 device
$ adb -s 8XV7N15C31003476 bugreport
保存旧版 bug 报告
默认情况下,bug 报告会保存在 /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
检查 bug 报告 ZIP 文件
默认情况下,ZIP 文件称为 bugreport-BUILD_ID-DATE.zip
。ZIP 文件可以包含多个文件,但最重要的文件是 bugreport-BUILD_ID-DATE.txt
。此文件就是 bug 报告,它包含系统服务 (dumpsys
)、错误日志 (dumpstate
) 和系统消息日志 (logcat
) 的诊断输出。系统消息包括设备抛出错误时的堆栈轨迹,以及从所有应用中使用 Log
类写入的消息。
ZIP 文件包含一个 version.txt
元数据文件,后者包含 Android 版本字母。启用 systrace 后,ZIP 文件还会包含 systrace.txt
文件。Systrace 工具可以获取并显示应用进程和其他 Android 系统进程的执行时间,从而帮助分析应用的性能。
dumpstate
工具会将文件从设备的文件系统复制到 ZIP 文件的 FS
文件夹下,以便您引用它们。例如,设备中的 /dirA/dirB/fileC
文件会在 ZIP 文件中生成 FS/dirA/dirB/fileC
条目。
图 3. bug 报告文件结构。
如需了解详情,请参阅阅读 bug 报告。
从用户那里获取报告
您自己使用应用时,获取 bug 报告非常有用,但最终用户无法轻松地与您分享这些类型的 bug 报告。如需从真实用户那里获取包含堆栈轨迹的崩溃报告,请利用 Google Play 和 Firebase 的崩溃报告功能。
Google Play 管理中心
您可以从 Google Play 管理中心获取报告,以便查看从 Google Play 安装您的应用的用户那里收集的有关崩溃和应用无响应 (ANR) 错误的数据。您可以查看过去六个月的数据。
如需了解详情,请参阅 Play 管理中心帮助内的查看崩溃和应用无响应 (ANR) 错误。
Firebase 崩溃报告
Firebase Crashlytics 报告会创建有关应用中出现的错误的详细报告。此报告会基于相似堆栈轨迹将错误分门别类,并会根据错误对用户所产生影响的严重程度进行分级。除自动发送的报告外,您还可以通过记录自定义事件获知导致应用崩溃的操作。
如需开始接收任何用户的崩溃报告,请向您的 build.gradle
文件添加 Firebase 依赖项。如需了解详情,请参阅 Firebase Crashlytics。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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/)."]]