Instrument your application via Dynatrace Android Gradle plugin

If your project has library modules, feature modules, multiple application modules, or just one build file, first check the corresponding section in Change Dynatrace Android Gradle plugin configuration based on the project structure. The steps required to set up the Dynatrace Android Gradle plugin might be slightly different for applications with such architectures.

Follow the steps below to instrument your Android app with the Dynatrace Android Gradle plugin.

  1. Ensure that the Maven Central repository is declared.

    Dynatrace is hosted on Maven Central. In the Gradle settings file, verify that mavenCentral() is added to the repositories blocks under pluginManagement and dependencyResolutionManagement. Check the official Android documentation to see what the Gradle settings file should look like.

    You might need to add mavenCentral() to all repositories blocks in the top-level build file.

  1. Add our plugin to the build script classpath.

    In the top-level build file, add the buildscript block with the dependencies block inside and add the classpath of the Dynatrace Android Gradle plugin (com.dynatrace.tools.android:gradle-plugin).

    In the top-level build file, find the dependencies block inside the buildscript block, and add the classpath of the Dynatrace Android Gradle plugin (com.dynatrace.tools.android:gradle-plugin) after the build script classpath of the Android Gradle plugin (com.android.tools.build:gradle).

    Use version 8.+ so that Gradle can automatically update our plugin when a new minor version is available. When Dynatrace releases a new major version, manually upgrade to the new version—the new major version might contain breaking changes, so manual adjustments are usually required.

  1. Apply our plugin and add its configuration snippet.

    Apply the Dynatrace Android Gradle plugin with the com.dynatrace.instrumentation plugin ID in the top-level build file.

    Then, add the code snippet from step 3 (Apply the Dynatrace plugin and add the plugin configuration) of the Android instrumentation wizard to have the correct applicationId and beaconUrl values.

    You can change the sampleConfig configuration name 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 applications in Dynatrace by using variant-specific configurations.

  1. Customize the plugin configuration.

    The Gradle snippet that you've copied from the Android instrumentation wizard contains the default plugin configuration. The same configuration is used for all Android build variants, and our plugin uses the default sensors and default OneAgent configuration values. For this reason, you might want to adjust the configuration of the Dynatrace Android Gradle plugin.

  1. optional Enhance mobile user experience data by using the OneAgent SDK for Android.

    With OneAgent SDK for Android, you can enrich the mobile user experience data. For example, user tagging or custom value reporting is only available via the OneAgent SDK.