Set up the Agentedit

Follow these steps to start reporting your Android application’s performance to Elastic APM:

Set up Gradleedit

First, add the Elastic APM agent plugin to your application’s build.gradle file as shown below:

// Android app's build.gradle file
plugins {
    id ""
    id "" version "[latest_version]" 

The Elastic plugin declaration must be added below the Android app plugin declaration ( and below the Kotlin plugin declaration (if used).

After adding the agent plugin, configure it. A minimal configuration sets the Elastic APM Server endpoint as shown below:

// Android app's build.gradle file
plugins {
    id "" version "[latest_version]" 

elasticApm {
    // Minimal configuration
    serverUrl = "https://your.elastic.server"

    // Optional
    serviceName = "your app name" 
    serviceVersion = "0.0.0" 
    apiKey = "your server api key" 
    secretToken = "your server auth token" 

You can find the latest version in the Gradle plugin portal.

Defaults to your android.defaultConfig.applicationId value.

Defaults to your android.defaultConfig.versionName value.

Defaults to null. More info on API Keys here.

Defaults to null.

When both secretToken and apiKey are provided, apiKey has priority and secretToken is ignored.

For projects using minSdk version < 26edit

Due to Android’s limited support for Java 8 features on devices with API level < 26, or in other words, older than Android 8.0, you must add Java 8+ desugaring support to apps with a minSdk version lower than 26. If you don’t, your app can crash when running on devices using Android OS versions older than 8.0. This is because the OpenTelemetry Java SDK, which this SDK is built upon, uses Java 8 features.

If your minSdk is 26 or higher, you can skip this step.

Set up your applicationedit

After syncing your project with the Gradle changes above, the Elastic APM agent needs to be initialized within your Application class. This example shows the simplest way to configure the agent:

// Your Application class

class MyApp extends {

    public void onCreate() {

Initialize the Elastic APM agent once.

Compile and runedit

All that’s left is to compile and run your application. That’s it!

(Optional) Manual set upedit

If you need to set up the Elastic SDK manually, without having to add the Gradle plugin as shown above, you’ll need to provide the following configuration parameters at runtime:

  • Set your app name, version, and environment name, as explained here.
  • Set your server connectivity parameters, as explained here.

Without the Gradle plugin, the Elastic SDK won’t be able to provide automatic instrumentations for its Supported technologies.

What’s next?edit

After initializing the agent (by using the gradle plugin), your application will automatically create traces for all OkHttp network requests (including those created by tools that make use of OkHttp, like Retrofit) and all Activity and Fragment starting methods.

Apart from the automatic instrumentation helped by the Gradle plugin, you’ll get automatic crash reports when an unexpected error occurs in your app, regardless of whether the Gradle plugin is available or not.

All of these events will contain a "Session ID" that links related events together—allowing you to make sense of and diagnose any issues that arise. Head to the APM app in Kibana to start exploring your data.

If you need to customize the Elastic APM agent to your project’s needs, see configuration. If you need to create your own custom transactions, see manual instrumentation.