Manual Configuration
Try out our new Jetpack Compose integration!
This feature is available starting from version 6.10.0
of the Sentry Android SDK. It automatically adds a breadcrumb and starts a transaction for each navigation or user interaction event.
Let us know if you have feedback through GitHub issues.
Installation
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
// Make sure mavenCentral is there.
repositories {
mavenCentral()
}
// Enable Java 1.8 source compatibility if you haven't yet.
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
// Add Sentry's SDK as a dependency.
dependencies {
implementation 'io.sentry:sentry-android:6.16.0'
}
The NDK integration comes packaged with the SDK and requires API level 16, though other levels are supported. If you're using multiple Sentry dependencies, you can add a bill of materials to avoid specifying the version of each dependency.
Configuration
Configuration is done via the application AndroidManifest.xml
Here's an example config which should get you started:
AndroidManifest.xml
<application>
<!-- Required: set your sentry.io project identifier (DSN) -->
<meta-data android:name="io.sentry.dsn" android:value="https://examplePublicKey@o0.ingest.sentry.io/0" />
<!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
<meta-data android:name="io.sentry.traces.user-interaction.enable" android:value="true" />
<!-- enable screenshot for crashes -->
<meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
<!-- enable view hierarchy for crashes -->
<meta-data android:name="io.sentry.attach-view-hierarchy" android:value="true" />
<!-- enable the performance API by setting a sample-rate, adjust in production env -->
<meta-data android:name="io.sentry.traces.sample-rate" android:value="1.0" />
<!-- enable profiling when starting transactions, adjust in production env -->
<meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />
</application>
Under the hood Sentry uses a ContentProvider
to initalize the SDK based on the values provided above. This way the SDK can capture important crashes and metrics right from the app start.
Additional options can be found on our dedicated options page.
If you want to customize the SDK init behaviour, you can still use the Manual Initialization method.
Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.
Verify
This snippet includes an intentional error, so you can test to make sure that everything's working as soon as you set it up:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.lang.Exception;
import io.sentry.Sentry;
public class MyActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
throw new Exception("This is a test.");
} catch (Exception e) {
Sentry.captureException(e);
}
}
}
To view and resolve the recorded error, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
Learn more about manually capturing an error or message in our Usage documentation.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- maven:io.sentry:sentry-android
- Version:
- 6.16.0
- Repository:
- https://github.com/getsentry/sentry-java