Instrumentation via Gradle plugin for Android

Version 8.x

This is documentation for the most recent version 8.x. It is only supported for AppMon 2018 October.

If you're using older version, see Gradle plugin for Android - version 7.x.

After the Dynatrace Android Gradle plugin is applied in the top-level build.gradle file, located in the root project directory, it can configure the subprojects of your Android project.

1. Find the build script classpath

Find the build script classpath of the Android Gradle plugin in the top-level build.gradle file, located in the root project directory.

The build script classpath of the plugin is in the dependencies block inside the buildscript block. The classpath value of the plugin is com.android.tools.build:gradle.

Download
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        // build script classpath of the Android Gradle plugin
        classpath 'com.android.tools.build:gradle:<version>'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

2. Add the Dynatrace Android Gradle plugin

Now, add the Dynatrace Android Gradle plugin to the build script classpath.

The build script classpath value com.dynatrace.tools.android:gradle-plugin should be added to the dependencies block. The Gradle automatically updates the plugin when a new plugin version is available. Therefore, it’s recommended that you use version 8.+. When Dynatrace releases a new major version, manually upgrade to the new version. The new major version might contain breaking changes and manual adjustments might be needed.

Download
buildscript {
    repositories {
    	google()
        jcenter() // hosts the Dynatrace Android Gradle plugin
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:<version>'
        // add this line to your build.gradle file
        classpath 'com.dynatrace.tools.android:gradle-plugin:8.+'
    }
}

allprojects {
    repositories {
        google()
        jcenter() // hosts the OneAgent SDK for Android
    }
}

3. Apply the Dynatrace Android Gradle plugin

Apply the Dynatrace Android Gradle plugin and add the configuration snippet.

Apply the Dynatrace Android Gradle plugin with the plugin id com.dynatrace.instrumentation in the top-level build.gradle file, located in the root project directory. Then determine the correct agentPath value (the address of your instrumented web or application server) and select a unique applicationId value.

Download
apply plugin: 'com.dynatrace.instrumentation'
dynatrace {
    configurations {
        sampleConfig {
            autoStart {
                applicationId '<YourApplicationID>'
                agentPath '<YourAgentPathUrl>'
            }
        }
    }
}

You can customize the configuration name sampleConfig to something more meaningful. You can also define different configurations for different Android build variants. For example, you can report your debug and release variants to different mobile apps in Dynatrace by using variant-specific configurations.

4. Customize your plugin configuration.

The Gradle snippet from the Dynatrace Instrumentation page only configures the endpoint for the Android Agent. It doesn't customize the behavior for the Dynatrace Android Gradle plugin. The same configuration is used for all Android build variants and the plugin uses the default sensors and default Android Agent configuration values. Use the configuration capabilities of the plugin to fine-tune your configuration.

5. Enhance mobile user experience data

With Android Agent SDK, you can enrich mobile user experience data. For example, features such as user tagging are only available via the Android Agent SDK.