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
- User Interactions (view click, scroll, swipe, etc.)
- Android fragment lifecycle events with Fragment Integration
- OkHttp requests with OkHttp Integration
- Apollo requests with Apollo Integration
- Timber logs with Timber Integration
- Navigation destination changes with Navigation 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 ability to collect user information when an event occurs.
- Performance Monitoring creates transactions for:
- Android activity transactions
- User interaction transactions (view click, scroll, swipe, and so on)
- Navigation transactions with Navigation Integration
- Android fragment spans with Fragment Integration
- Cold and warm app start
- Slow and frozen frames
- OkHttp request spans with OkHttp Integration
- SQLite and Room query spans with Room and SQLite Integration
- File I/O spans with File I/O Integration
- Apollo request spans with Apollo Integration
- Distributed tracingThe process of logging the events that took place during a request, often across multiple services.through OkHttp and Apollo integrations
- Application Not Responding (ANR) reported if the application is blocked for more than five seconds
- HTTP Client Errors
- Screenshot attachments for errors
- View Hierarchy attachments for errors
- 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.
Auto-Installation With the Sentry Android Gradle Plugin
To install the plugin, add it your app module's build.gradle
file:
app/build.gradle
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id "com.android.application"
id "io.sentry.android.gradle" version "3.4.2"
}
The plugin will automatically add the latest version of the Sentry SDK for Android as a dependency.
Manual Installation
If you don't want the Sentry Gradle plugin to install the Sentry SDK automatically for you, you can define the dependency directly to your build.gradle
file:
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.13.1'
}
NDK integration is packed with the SDK and requires API level 16, though other levels are supported.
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.
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.13.1
- Repository:
- https://github.com/getsentry/sentry-java