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.
-
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 thebuildscript
block. The classpath value of the plugin iscom.android.tools.build:gradle
.buildscript { repositories { google() mavenCentral() } dependencies { // build script classpath of the Android Gradle plugin classpath 'com.android.tools.build:gradle:<version>' } }
buildscript { repositories { google() mavenCentral() } dependencies { // build script classpath of the Android Gradle plugin classpath("com.android.tools.build:gradle:<version>") } }
-
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 thedependencies
block. The Gradle automatically updates the plugin when a new plugin version is available. Therefore, it’s recommended that you use version8.+
. 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() 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.+' } }
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.+") } }
-
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 correctapplicationId
andbeaconUrl
value.apply plugin: 'com.dynatrace.instrumentation' dynatrace { configurations { sampleConfig { autoStart { applicationId '<YourApplicationID>' beaconUrl '<ProvidedBeaconURL>' } } } }
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 yourdebug
andrelease
variants to different mobile apps in Dynatrace by using variant-specific configurations. -
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.
-
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.