Dynatrace Android Gradle plugin
You can use the Dynatrace Android Gradle plugin only for Android projects that use the Android Gradle plugin to build the app. You should apply the Dynatrace Android Gradle to the top-level build file (either
build.gradle.kts), which is located in the root project directory. This approach allows the plugin to properly configure the Android subprojects and establish the auto-instrumentation process as part of the Android build process.
In a couple of months, we'll stop setting cookies to file scheme domains for hybrid applications. See Disable cookies for file domains for more details and action items.
Jetpack Compose auto-instrumentation is enabled by default starting with Dynatrace Android Gradle plugin version 8.271.
Gradle version 6.1.1+
Android Gradle plugin version 4.0+
- JVM: Java 11+
Starting with OneAgent for Android version 8.261, Dynatrace no longer supports Java 8 for the Dynatrace Android Gradle plugin because Java 11 is required for the latest version of the Android Gradle plugin API.
The Dynatrace Android Gradle plugin uses bytecode instrumentation to instrument your app. It can instrument the source files of all subprojects and third-party libraries. Performance-wise, bytecode instrumentation is quick and has a low impact on the build time. By providing support for incremental builds and the build cache, the instrumentation of apps will be almost unnoticed.
Java and Kotlin: The Dynatrace Android Gradle plugin supports the instrumentation of Java and Kotlin classes. It also supports other JVM languages.
Obfuscations and optimization: The auto-instrumentation process is completed before the R8 Gradle task. If you use another tool for obfuscation, you must ensure that the obfuscation task is executed after the auto-instrumentation process.
Security and APK-hardening tools: Bytecode instrumentation happens before obfuscation and before Android Dexer (D8) transforms the
.dexbytecode that can be executed in the Android Runtime. Therefore, the plugin can ensure maximum compatibility with other security-focused and APK-hardening tools that calculate checksums for the DEX code, such as DexGuard and Arxan.
The Android Gradle plugin only instruments the
AndroidManifest.xml and other
.class files. It doesn’t instrument the following components:
- Native code, such as code written with the NDK
- Web components, such as
- Resource files, such as layout
Compatibility with other monitoring tools
There might be compatibility issues with other performance monitoring plugins, especially when these plugins instrument OneAgent for Android. We recommend either using only one performance monitoring plugin or verifying via manual testing that the plugins you've chosen are compatible.
The Dynatrace Android Gradle plugin is compatible with the Firebase Performance Monitoring plugin. However, there are some limitations. For details, see Why am I missing web requests when I use the Firebase plugin? in the FAQ.
The Dynatrace Android Gradle plugin supports Gradle build-specific capabilities, including the following:
Faster incremental builds by modifying only classes and libraries, thereby reducing instrumentation time.
- Build cache to reduce build time by reusing outputs produced by other builds.
- Dynatrace Android Gradle plugin version 8.257+ Configuration cache to reduce build time by reusing the cached result of the configuration phase.
- Apply Changes for pushing code and resource changes to a running app without having to restart it. The app must be restarted only when the configuration of the plugin or OneAgent is changed.
- Build processes for Android App Bundles and APKs.
- Multiple APK builds via the
splitsblock so that the instrumentation step is executed only once.
- Support for Kotlin DSL in
- Android library projects: The Dynatrace Android Gradle plugin auto-instruments only Android application projects. It doesn't support the auto-instrumentation of stand-alone Android library projects. Our plugin auto-instruments the internal libraries if you add them as a dependency to your Android application project.
- Firebase Performance Monitoring: The Firebase Performance Monitoring plugin version 1.4.0+ used with Android Gradle plugin version 4.2.0 is incompatible with the Dynatrace Android Gradle plugin. For a solution, see Why am I missing web requests when I use the Firebase plugin? in the FAQ.
- Android Gradle plugin
excludesproperty: With the
excludes property of the Android Gradle plugin, you can disable instrumentation for specific classes. This property is similar to the
excludeproperty of the Dynatrace Android Gradle plugin. However, when you use the Dynatrace property, our plugin still instruments some very important classes to ensure that instrumentation is always valid. With the Android
excludesproperty, all the specified classes aren't instrumented, which might negatively affect the instrumentation.
The Android Gradle plugin provides a wide range of configuration options to customize your Android application build and the monitored mobile user experience data.
The Gradle snippet from the Instrumentation page and the Gradle snippets from the documentation contain sample names for variant-specific configuration, such as
sampleConfig. To understand this better, see how variant-specific configurations are used.
Configure monitoring capabilities
The following options can be used to customize OneAgent SDK for Android monitoring capabilities and fine-tune the auto-instrumentation process.
Configure instrumentation processes
The plugin also provides additional configuration options to customize the instrumentation process:
Adjust OneAgent configuration
The following configuration options can be used to adjust the default OneAgent configuration:
These options are especially helpful when used along with the automatic OneAgent startup. They can also be used to adjust the OneAgent configuration when approached with the manual startup, but you need to be careful because the settings can easily be overridden with
Adjust Dynatrace Android Gradle plugin configuration based on the project structure
Our plugin scans all subprojects and configures the auto-instrumentation process for your application modules. Other modules are unaffected by the plugin. In this case, you might need to adjust the instrumentation process for an Android project with: