Android
On this page, we get you up and running with Sentry's Android SDK, automatically reporting errors and exceptions in your application.
If you don't already have an account and Sentry project established, head over to sentry.io, then return to this page.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Sentry captures data by using an SDK within your application's runtime. These are platform-specific and allow Sentry to have a deep understanding of how your application works.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling. To enable tracing and/or profiling, click the corresponding checkmarks to get the code snippets.
We recommend installing the SDK through our Sentry Wizard by running the following command inside your project directory:
brew install getsentry/tools/sentry-wizard && sentry-wizard -i android
This will patch your project and configure the SDK. You only need to patch the project once, then you can add the patched files to your version control system. If you prefer, you can also set up the SDK manually or follow the instructions below to adapt the configuration.
The following tasks will be performed by the Sentry Wizard
The wizard will prompt you to log in to Sentry. It'll then automatically do the following steps for you:
- Update your app's
build.gradle
file with the Sentry Gradle plugin and configure it - Update your
AndroidManifest.xml
with the default Sentry configuration - Create
sentry.properties
with an auth token to upload proguard mappings (this file is automatically added to.gitignore
) - Add an example error to your app's Main Activity to verify your Sentry setup
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 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>
Verify that your app is sending events to Sentry by adding the following snippet, which includes an intentional error. You should see the error reported in Sentry within a few minutes.
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);
}
}
}
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").