Instrumentation via Dynatrace Android Gradle plugin

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

  1. Find the build script classpath of the Android Gradle plugin in the root build.gradle file.

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.

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}
  1. 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.

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
    }
}
  1. 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 root build.gradle file. Then, copy the Gradle snippet from the Dynatrace Instrumentation page to configure the correct applicationId and beaconUrl value.

apply plugin: 'com.dynatrace.instrumentation'
dynatrace {
    configurations {
        sampleConfig {
            autoStart {
                applicationId '<YourApplicationID>'
                beaconUrl '<ProvidedBeaconURL>'
            }
        }
    }
}

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.

  1. Customize your plugin configuration.

The Gradle snippet from the Dynatrace Instrumentation page only configures the endpoint for the OneAgent. 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 OneAgent configuration values. Use the configuration capabilities of the plugin to fine-tune your configuration.

  1. Enhance mobile user experience data by using the OneAgent SDK for Android. With OneAgent SDK for Android, you can enrich mobile user experience data. For example, features such as user tagging are only available via the OneAgent SDK.