Android

Features:

  • The Native Development Kit (NDK), the set of tools that that allows you to use C and C++ code with Android, is packed with the SDK.
  • Events enriched with device data
  • Offline caching when a device is offline; we send a report once we receive another event
  • Breadcrumbs automatically captured for:
    • Android activity lifecycle events
    • Application lifecycle events (lifecycle of the application process)
    • System events (low battery, low storage space, airplane mode started, shutdown, changes of the configuration, and so forth)
    • App. component callbacks
  • Release Health tracks crash free users and sessions
  • Attachments enrich your event by storing additional files, such as config or log files.
  • User Feedback provides the abiity to collect user information when an event occurs.
  • Performance Monitoring creates transactions
  • Application Not Responding (ANR) reported if the application is blocked for more than five seconds
  • Code samples provided in both Kotlin and Java as the Android SDK uses both languages
  • We provide a sample application for our Android users
  • Our video tutorial visually demonstrates how to set up our SDK

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.2.0'
}

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").