Android
Sentry's Android SDK reports an error automatically whenever a thrown exception goes uncaught in your application causing the application to crash.
The SDK builds a crash report that persists to disk and tries to send the report right after the crash. Since the environment may be unstable at the crash time, the report is guaranteed to send once the application is started again. This process for sending a report is true if there is a fatal error in your native code as well as for the NDK. In addition, the NDK is not only catching unhandled exceptions but is also set as a signal handler to react to signals from the OS.
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 the application is restarted
- 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
- Android fragment lifecycle events with Fragment Integration
- OkHttp requests with OkHttp Integration
- Apollo requests with Apollo Integration
- Timber logs with Timber Integration
- 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 for:
- Android activity transactions
- Android fragment spans with Fragment Integration
- Cold and warm app start spans and measurements with Automatic Instrumentation
- Slow and frozen frames measurements with Automatic Instrumentation
- OkHttp request spans with OkHttp Integration
- SQLite and Room query spans with Sentry Android Gradle Plugin
- Apollo request spans with Apollo Integration
- Distributed tracing through OkHttp and Apollo integrations
- 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
// 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:7.13.0'
}
NDK integration is packed with the SDK and requires API level 16, though other levels are supported.
Sentry's Android SDK depends on Gson as a transitive dependency; the minimum required version is 2.7.
If you are using multiple Sentry dependencies, you can add a bill of materials to avoid specifying the version of each dependency.
Configure
Configuration should happen as early as possible in your application's lifecycle.
Configuration is done via AndroidManifest.xml
:
AndroidManifest.xml
<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:
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);
}
}
}
Learn more about manually capturing an error or message in our Usage documentation.
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.
- Package:
- maven:io.sentry:sentry-android
- Version:
- 7.13.0
- Repository:
- https://github.com/getsentry/sentry-java