Manual Configuration

If you don't want the Sentry Gradle plugin to install the Sentry SDK automatically, you can define the dependency directly in the build.gradle file of your app module.

app/build.gradle
Copied
dependencies {
    implementation 'io.sentry:sentry-android:7.8.0'
}

Initialize the SDK manually when you need to provide additional configuration to the SDK that cannot be specified in the manifest.

To initialize the SDK manually, disable the auto initialization. You can do so by adding the following line into your manifest:

AndroidManifest.xml
Copied
<application>
    <meta-data android:name="io.sentry.auto-init" android:value="false" />
</application>

Or, to completely remove the merging of the ContentProvider:

AndroidManifest.xml
Copied
<application>
    <provider
        android:name="io.sentry.android.core.SentryInitProvider"
        android:authorities="${applicationId}.SentryInitProvider"
        tools:node="remove" />

    <provider
        android:name="io.sentry.android.core.SentryPerformanceProvider"
        android:authorities="${applicationId}.SentryPerformanceProvider"
        tools:node="remove" />
</application>

The next step is to initialize the SDK directly in your code.

The SDK can catch errors and crashes only after you've initialized it. So, we recommend calling SentryAndroid.init in the instance your Application class right after the application is created. If you don't have a custom Application class yet, checkout the official docs on how to create one.

Configuration options will be loaded from the manifest so that you don't need to have the static properties in your code. In the init method, you can provide a callback that will modify the configuration and also register new options.

Copied
import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroid;
import android.app.Application;

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();

    SentryAndroid.init(this, options -> {
      options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");
      // Add a callback that will be used before the event is sent to Sentry.
      // With this callback, you can modify the event or, when returning null, also discard the event.
      options.setBeforeSend((event, hint) -> {
        if (SentryLevel.DEBUG.equals(event.getLevel()))
          return null;
        else
          return event;
      });
    });
  }
}
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").