---
metadata:
  - name: generator
    content: Diplodoc Platform v5.64.0
alternate:
  - https://boost.yandex.com/doc/en/analytics/content/mobile-reports/anr.md
  - https://boost.yandex.com/doc/ru/analytics/content/mobile-reports/anr.md
  - https://boost.yandex.com/doc/zh/analytics/content/mobile-reports/anr.md
  - href: https://boost.yandex.com/doc/zh/analytics/content/mobile-reports/anr.md
    type: text/markdown
    title: Markdown version
  - href: https://boost.yandex.com/doc/zh/llms.txt?revision=r21738064
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://boost.yandex.com/doc/zh/llms.txt?revision=r21738064

# ANR

当运行在主线程上的任务耗时过长时，就会发生 ANR（应用未响应）错误。 在此期间，应用程序界面停止更新并不响应用户操作。 结果会弹出一个对话框，提示用户等待或关闭应用。

报告显示ANR最常发生的时间。 使用这些信息来准备修复。

报告中的数据可以按会话类型过滤：

- 仅后台会话;
- 没有后台会话；
- 对于所有会话。

您可以配置ANR监控机制并设置超时时间：

{% list tabs %}

- Android

   1. [启用ANR监控](https://yastatic.net/s3/doc-binary/src/dev/appmetrica/ru/javadoc/io/appmetrica/analytics/AppMetricaConfig.Builder.html#withAnrMonitoring(boolean)). 默认是禁用的。

   1. [设置超时时间](https://yastatic.net/s3/doc-binary/src/dev/appmetrica/ru/javadoc/io/appmetrica/analytics/AppMetricaConfig.Builder.html#withAnrMonitoringTimeout(int))，以指示线程无响应多长时间后才会记录ANR错误。 默认和最小值为5秒。

   {% list tabs group=instructions %}

   - Java

      ```java translate=no
      // Creating an extended library configuration.
      Analytics moduleConfig config = Analytics moduleConfig.newConfigBuilder(API_KEY)
            // Enabling ANR monitoring. The default value is false.
            .withAnrMonitoring(true)
            // Override the ANR timeout if needed. The default value is 5.
            .withAnrMonitoringTimeout(7)
            .build();
      // Initializing the AppMetrica SDK.
      Analytics module.activate(getApplicationContext(), config);
      ```

   - Kotlin

      ```kotlin translate=no
      // Creating an extended library configuration.
      val config = Analytics moduleConfig.newConfigBuilder(API_KEY)
         // Enabling ANR monitoring. The default value is false.
            .withAnrMonitoring(true)
            // Override the ANR timeout if needed. The default value is 5.
            .withAnrMonitoringTimeout(7)
         .build()
      // Initializing the AppMetrica SDK.
      Analytics module.activate(applicationContext, config)
      ```

   {% endlist %}

- iOS

  {% list tabs group=instructions %}

  - Swift

      ```swift translate=no
      var configuration = Analytics moduleCrashesConfiguration()

      // Enables detection of situations when the main application thread stops responding (ANR)
      configuration.applicationNotRespondingDetection = true 

      // Sets the time interval that the watchdog will wait before reporting the ANR status
      configuration.applicationNotRespondingWatchdogInterval = 4.0 

      // Sets the frequency with which the watchdog will check the ANR status
      configuration.applicationNotRespondingPingInterval = 0.1 

      Analytics moduleCrashes.crashes().setConfiguration(configuration)
      ```

      或

      ```swift translate=no
      Analytics moduleCrashes.crashes().enableANRMonitoring()
      ```

  - Objective-C  

      ```obj-c translate=no
      AMAAppMetricaCrashesConfiguration *configuration = [[AMAAppMetricaCrashesConfiguration alloc] init];

      // Enables detection of situations when the main application thread stops responding (ANR)
      configuration.applicationNotRespondingDetection = YES; 

      // Sets the time interval that the watchdog will wait before reporting the ANR status
      configuration.applicationNotRespondingWatchdogInterval = 4.0; 

      // Sets the frequency with which the watchdog will check the ANR status
      configuration.applicationNotRespondingPingInterval = 0.1; 

      [[AMAAppMetricaCrashes crashes] setConfiguration:configuration];
      ```
      
      或

      ```obj-c translate=no
      [[AMAAppMetricaCrashes crashes] enableANRMonitoring];
      ```
      
  {% endlist %}

{% endlist %}   

## 报告期 {#period-anr}

您可以查看某一天的报告或为特定时间段生成报告。

<!-- source: zh/analytics/content/mobile-reports/_includes/period.md -->
要设置自定义报告期，请使用![日期](../../_images/button-date.png)按钮。 所选时间间隔可以按小时、天、周或月进行分组。
<!-- endsource: zh/analytics/content/mobile-reports/_includes/period.md -->

## 分组数据 {#group-anr}

报告中的数据可以按以下方式分组：

- ANR 组
- App 版本
- Device
- OS版本
- Manufacturer

## 指标 {#measure}

![指标](../../_images/anr-info-zh.png)

以下是可用于分析的指标：

- **ANRs**：错误数量。
- **设备**：在选定的时间段内至少报告过一次错误的设备数量。
- **% 的所有设备**：在选定时间段内运行应用的总设备数中，注册了错误的设备所占的百分比。
- **首次注册错误的应用版本**：首次记录错误的应用版本。
- **最后一次重现**：错误最后被记录的应用版本。

您可以访问ANR组详情页面。 要做到这一点，点击右上角的 ANR 组名称。

## ANR 符号化 {#symbolization-anr}

{% note info %}

无法为之前的构建重新生成映射文件。 但是，如果您有由我们的[崩溃插件](https://boost.yandex.com/doc/zh/analytics/content/sdk/android/analytics/android-crash.md)为之前的构建生成的归档文件，可以手动上传它们。

{% endnote %}

如果在应用构建过程中未上传映射文件或 dSYM 文件，组列表中会出现关于未符号化 ANR 的警告。

![警告](../../_images/symbolization-anr-zh.png){style="border: solid 1px #cccccc; max-width: 330px;"}

如何对ANR进行符号化：

{% list tabs %}

- Android

   ![安卓](../../_images/mapping-upload-manual-zh.png){style="border: solid 1px #cccccc; max-width: 800px;"}

   要上传映射文件：

   1. 打开**设置** → **崩溃**。
   2. 确保为 Android 选中文件上传。
   3. 选择要上传的文件。

   您可以在应用的**设置** → **崩溃**页面查看缺失文件的列表Analytics module。

- iOS

   上传 [dSYM 文件（iOS）](https://boost.yandex.com/doc/zh/analytics/content/data-collection/upload-dsym.md)。 您可以在应用的**设置** → **崩溃**页面查看缺失文件的列表Analytics module。

{% endlist %}

## 查看ANR日志 {#show-crash-log-anr}

要查看日志：

1. 点击所需 ANR 组的名称以打开该组事件的报告。 数据将显示为原始报告中选择的同一会话类型。 如果需要，您可以选择不同的会话类型。
2. 在表格中，点击**打开 ANR 日志**。

日志显示设备信息和ANR详情。

从日志中进入个人卡片，查看导致 ANR 的前置事件。 要做这一步，点击**查看会话事件**。

## 添加评论 {#comment-anr}

如果需要，您可以为 ANR 添加评论。 这在多个开发人员查看报告时会很有用。 例如，您可以在 Yandex Tracker 的评论中添加指向问题的链接。

要添加评论，请打开相应的组，然后在**评论**字段中输入文本。

## 关闭ANR {#close-anr}

关闭固定的ANR以从报告中移除它们。 已关闭的ANR会在检测到它们出现在之前未发现它们的版本中时自动重新打开。

要关闭 ANR，请打开相关组。 在右上角，将**ANR 组状态**设置为**已关闭**。

![ANR 组状态](../../_images/anr-status-zh.png){style="border: solid 1px #cccccc; max-width: 200px;"}

## 数据导出 {#export}

您可以将 ANR 日志描述导出为 TXT 文件。 要做这一步，打开相应的 ANR 组，然后点击 **打开 ANR 日志**→ **导出**。

### 了解更多 {#learn-more}

- [在 Unity-Android 上调试和修复 ANR](https://developer.android.com/games/engines/unity/unity-anrs?hl=en)
- [在 Android 上调试和修复 ANR](https://developer.android.com/topic/performance/anrs/diagnose-and-fix-anrs?hl=en)
- [崩溃和错误](https://boost.yandex.com/doc/zh/analytics/content/data-collection/about-crashes-and-errors.md)
- [在 Android 上上传映射文件和调试符号](https://boost.yandex.com/doc/zh/analytics/content/data-collection/upload-mapping.md)
- [上传 iOS 的 dSYM 文件](https://boost.yandex.com/doc/zh/analytics/content/data-collection/upload-dsym.md)

<!-- source: zh/analytics/content/_includes/feedback-button.md -->
如果您没有找到所需答案，可以通过反馈表单提交您的问题。 请尽可能详细地描述问题。 如果可能，请附上截图。

<a href="../troubleshooting/feedback-new">
  <span class="button">联系支持</span>
</a>

<a href="../troubleshooting/feedback-docs">
  <span class="button">为文档提出改进建议</span>
</a>
<!-- endsource: zh/analytics/content/_includes/feedback-button.md -->
