• Home
  • Platform modules
  • Digital Experience
  • Mobile applications
  • Android
  • Plugin
  • Instrumentation via Dynatrace Android Gradle plugin

Instrumentation via Dynatrace Android Gradle plugin

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 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.

    gradle
    buildscript { repositories { google() mavenCentral() } dependencies { // build script classpath of the Android Gradle plugin classpath 'com.android.tools.build:gradle:<version>' } }
    gradle
    buildscript { repositories { google() mavenCentral() } dependencies { // build script classpath of the Android Gradle plugin classpath("com.android.tools.build:gradle:<version>") } }
  2. 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.

    gradle
    buildscript { repositories { google() mavenCentral() // 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.+' } }
    gradle
    buildscript { repositories { google() mavenCentral() // hosts the Dynatrace Android Gradle plugin } dependencies { classpath("com.android.tools.build:gradle:<version>") // add this line to your build.gradle.kts file classpath("com.dynatrace.tools.android:gradle-plugin:8.+") } }
  3. 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, copy the Gradle snippet from the Dynatrace Instrumentation page to configure the correct applicationId and beaconUrl value.

    gradle
    apply plugin: 'com.dynatrace.instrumentation' dynatrace { configurations { sampleConfig { autoStart { applicationId '<YourApplicationID>' beaconUrl '<ProvidedBeaconURL>' } } } }
    gradle
    apply(plugin = "com.dynatrace.instrumentation") configure<com.dynatrace.tools.android.dsl.DynatraceExtension> { configurations { create("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.

  4. 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.

  5. 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.