Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions docs/platforms/android/troubleshooting/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,37 @@ 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}
<application>
<meta-data android:name="io.sentry.additional-context" android:value="false" />
</application>
```

```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)
Expand All @@ -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)
Expand Down Expand Up @@ -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?) {
Expand Down
Loading