Android

Features:

On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your application.

Don't already have an account and Sentry project established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

To install the Android SDK, add it your build.gradle file:

build.gradle
Copied
// 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:5.4.3'
}

Configure

Configuration should happen as early as possible in your application's lifecycle.

Configuration is done via AndroidManifest.xml:

AndroidManifest.xml
Copied
<application>
  <meta-data android:name="io.sentry.dsn" android:value="https://examplePublicKey@o0.ingest.sentry.io/0" />
</application>

Or, if you are manually instrumenting Sentry, follow the Manual Initialization configuration.

Verify

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:

Copied
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.

Help improve this content
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").