ANR and App Hangs for Kotlin Multiplatform

Configure Android ANR and Apple App Hang detection from shared Kotlin Multiplatform code.

Sentry reports when your app's main thread becomes unresponsive so you can investigate the code that blocked it. The KMP SDK uses the native Android and Apple SDKs to detect these events.

Use KMP SDK 0.5.0 or later to configure detection through shared options:

  • Android: Application Not Responding (ANR) events.
  • iOS, macOS, and tvOS: App Hang events.

Both detection options are enabled by default. To disable either feature, add the corresponding option to your shared initializer:

commonMain/SentrySetup.kt
Copied
import io.sentry.kotlin.multiplatform.Sentry

fun initializeSentry() {
    Sentry.init { options ->
        options.dsn = "___PUBLIC_DSN___"
        options.isAnrEnabled = false // Android
        options.enableAppHangTracking = false // Apple
    }
}

The anrTimeoutIntervalMillis option controls the watchdog detector's timeout in milliseconds. Its default is 5000 (five seconds). Set it in your initializer to change how long the main thread can remain blocked before that detector reports an ANR.

On Android 11 and newer, the native SDK uses the operating system's ApplicationExitInfo records. Changing anrTimeoutIntervalMillis does not change the operating system's ANR threshold. See the Android ANR guide for detection behavior and reporting differences.

See the Apple App Hangs guide for configuration, limitations, and guidance on using MetricKit for system-provided hang diagnostics.

Upload the relevant debug files so Sentry can display readable stack traces for ANR and App Hang events. Follow the Debug Symbols guide for Android mapping files and Apple debug symbols.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").