diff --git a/docs/platforms/android/troubleshooting/index.mdx b/docs/platforms/android/troubleshooting/index.mdx index b6afa112d639db..6aa9e8794aebc8 100644 --- a/docs/platforms/android/troubleshooting/index.mdx +++ b/docs/platforms/android/troubleshooting/index.mdx @@ -28,9 +28,10 @@ android { } ``` -## Sentry Android SDK Causes ANR +## Sentry Android SDK Causes ANR or StrictMode violations -Since version `6.1.1` of the Sentry SDK for Android, you can opt-out of some additional device context. +The Sentry Android SDK may trigger ANRs or StrictMode violations due to minimal file I/O operations required for event processing and context collection. +Since version `6.1.1` of the Sentry SDK for Android you can reduce violations by disabling additional context collection: ```xml {tabTitle:AndroidManifest.xml} @@ -38,14 +39,26 @@ Since version `6.1.1` of the Sentry SDK for Android, you can opt-out of some add ``` -```java {tabTitle:MyFile.java} -options.setCollectAdditionalContext(false); +```java {tabTitle:MyApplication.java} +SentryAndroid.init(this, options -> { + options.setDsn("___PUBLIC_DSN___"); + options.setCollectAdditionalContext(false); +}); ``` -[More context in the PR](https://github.com/getsentry/sentry-java/pull/2100) that added this option. +```kotlin {tabTitle:MyApplication.kt} +SentryAndroid.init(this) { options -> + options.dsn = "___PUBLIC_DSN___" + options.collectAdditionalContext = false +} +``` + +This reduces file I/O operations during event processing but you'll lose some device context information like battery level, memory usage, and file storage state. +Note that this won't eliminate all violations as certain features like app start crash detection require minimal file I/O operations. The motivation for it is that some of the Android API's the Sentry SDK relies on to add additional context, can be slow in some devices. -For example, the following stack traces: + +For example, this stack trace shows connectivity checking causing ANRs: ``` #00 pc 000000000007550c /apex/com.android.runtime/lib64/bionic/libc.so (syscall+28) @@ -72,6 +85,8 @@ For example, the following stack traces: at io.sentry.HubAdapter.captureEvent (HubAdapter.java:29) ``` +This one shows battery level checking causing ANRs: + ``` #00 pc 0000000000086f8c /apex/com.android.runtime/lib64/bionic/libc.so (syscall+28) #00 pc 00000000001b27a4 /apex/com.android.art/lib64/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+148) @@ -105,7 +120,7 @@ This is due to a [missing feature in the JVM](https://youtrack.jetbrains.com/iss Let's show an example. Here is an Activity with an inline function throwing an Exception. -``` +```kotlin class MyActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {