# Add Dynatrace gradle plugin in Android

**URL:** <https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389>\
**Category:** Real User Monitoring\
**Tags:** android, mobile-monitoring\
**Created:** [October 17, 2024, 12:36pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389 "2024-10-17T12:36:32Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 17, 2024, 12:36pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/1 "2024-10-17T12:36:32Z")

</div>

I am trying to add dynatrace gradle plugin in my application, when I am adding plugin by following the documentation and adding it to top level gradle, getting this issue

_it is too late to add actions as the callbacks already executed. did you try to call beforevariants or onvariants from the old variant api ‘applicationvariants’ for instance ? you should always call before variants or variants directly from the android components dsl block._

and when using it in app level gradle its not working, also tried turning off dynatrace.ignoreBuildwarning&nbsp;  
I am using groovy gradle and its an old project. please suggest something if someone has tried this already

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [October 17, 2024, 1:03pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/2 "2024-10-17T13:03:52Z")

</div>

Hello&nbsp;[@devggaurav](https://community.dynatrace.com/user/82013)

- It’s better to remove the old instrumentation configurations from the mobile development part and from Dynatrace as well.
- Remove the caches.
- Ensure the Cluster AG is having publicly accessible IP address and the [RUM constraints](https://docs.dynatrace.com/docs/shortlink/rum-firewall#mobile-rum) are allowed.
- Create a new mobile app in Dynatrace and use the cluster AG as beacon endpoint or if you’re using a
- Follow the Gradle instrumentation from scratch, hopefully you won’t expose further issues.

**DT Resources:**

- [Mobile applications in RUM Classic — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/mobile-applications-landing#instrument-android-apps)
- [Configure data privacy settings for mobile applications in RUM Classic — Dynatrace Docs](https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/additional-configuration/configure-rum-privacy-mobile)
- [Mobile applications in RUM Classic — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/mobile-applications-landing#additional-configuration)

 ![2024-10-17_16h57_41.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/b3a397b3d6c47be4f1e14c15910965937f2ff0cf.png)

**If The mobile app servers are monitored by Oneagent use the third option**

 ![2024-10-17_17h01_05.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/9/e9e1b99a79ec5efc19e4d02b7b085307a8704318.png)

**For the ENV AG**

 ![2024-10-17_17h02_14.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/9/891f0ce67402adaae05b400db0911ecaa4255468.png)

KR,

Peter

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 17, 2024, 1:15pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/3 "2024-10-17T13:15:44Z")

</div>

I tried same applicationId and beaconUrl with a dummy app first, can it be a case that same applicationID and beaconUrl can not be used for two apps ?

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [October 17, 2024, 1:26pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/4 "2024-10-17T13:26:40Z")

</div>

Hello&nbsp;[@devggaurav](https://community.dynatrace.com/user/82013)

For the RUM either mobile /&nbsp; web&nbsp; / custom to work perfectly:

1. Dedicated Application to each app so it’s impossible to use the same app id for duplicated instrumentation.
2. The beacon should be unique as well.
3. So based on the instrumentation method your configuration parameters should be unique.

It’s better to start a fresh instrumentation in collaborative manner including NW and FW team allowing the attached&nbsp;[Infrastructure pass-through requirements for RUM Classic — Dynatrace Docs](https://docs.dynatrace.com/docs/platform-modules/digital-experience/web-applications/initial-setup/firewall-constraints-for-rum)

and DT admin creates deletes all this old mobile app related configurations and create a new app, ask for the new configurations from the instrumentation wizard it will contain the application ID and beacon endpoint definitely.

Start an new instrumentation journey and keep the good work up&nbsp;:man\_technologist::dynaspin:😉😊

KR,

Peter

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 17, 2024, 2:25pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/5 "2024-10-17T14:25:07Z")

</div>

Can you suggest oneAgent SDK documentation for mobile application ? will that have some banefits ? which one is more convenient way to use ?

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [October 17, 2024, 3:21pm UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/6 "2024-10-17T15:21:25Z")

</div>

Hello&nbsp;[@devggaurav](https://community.dynatrace.com/user/82013)

It depends on the mobile development framework you will instrument Android 😊or iOS 🤗or what exactly to provide the proper resources.

**As simple as that** :

1. [Instrumentation via OneAgent SDK for Android](https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/instrument-android-app/instrumentation-via-oneagent-sdk/oneagent-sdk-for-android)
2. [Mobile Apps Instrumentations](https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications)

 ![2024-10-17_19h11_51.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/6e055c58cc21f8ec41f37df2dfe8f570eeaf0c76.png)

 ![2024-10-17_19h13_47.png](https://global.discourse-cdn.com/dynatrace/original/3X/d/9/d9b1ef126a59b69881ed23fd9be7fc4533274321.png)

Tip:

- If you’re not the mobile app developer, engage the mobile app in call and share Dynatrace documentation as per the development framework, it will be easy to decide the most convenient method.
- If the mobile app servers are monitored in Dynatrace, it will facilitate the instrumentation and detection of calling services, …etc.

Hoping this add value.

BR,

Peter

---

<div class="post-metadata">

**Author:** ![Thomas\_Wirth1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_wirth1/32/1776_2.png) [@Thomas\_Wirth1](https://community.dynatrace.com/u/Thomas_Wirth1)\
**Post date:** [October 18, 2024, 8:48am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/7 "2024-10-18T08:48:18Z")

</div>

Theoretically, the _applicationId_ and _beaconUrl_ can be used for multiple applications, because there is no limitation by Dynatrace. But this approach should be avoided.  
Dynatrace recommends to use a different _applicationId_ for every mobile application, because the&nbsp; dashboards will give you a proper overview of the application health state based on all reported data.  
Some customers prefer to combine their iOS and Android apps into one mobile application and then use the OS filtering option to get the platform-specific metrics. This is the only scenario, where the usage of the same applicationId value is fine.

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 18, 2024, 8:59am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/8 "2024-10-18T08:59:47Z")

</div>

I successfully added oneAgent SDK in my android application, with different applicationID and beacon URL, and enabled all, but I am not able to trace web requests from app automatically on dashboard, I want to track all of them , not using any third party web request, all are http, is there some config I am missing

```auto
.withUserOptIn(true)
    .withCrashReporting(true)
    .withActivityMonitoring(true)
    .withDebugLogging(true)
    .withStartupLoadBalancing(true)
    .withHybridMonitoring(true)

```

---

<div class="post-metadata">

**Author:** ![Peter\_Youssef](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/peter_youssef/32/14668_2.png) [@Peter\_Youssef](https://community.dynatrace.com/u/Peter_Youssef)\
**Post date:** [October 18, 2024, 9:24am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/9 "2024-10-18T09:24:30Z")

</div>

Hello&nbsp;[@devggaurav](https://community.dynatrace.com/user/82013)

Good to hear that.

Kindly follow the attached procedure to configure the web request tracing :&nbsp;[web-request-monitoring](https://docs.dynatrace.com/docs/shortlink/oneagent-sdk-for-android#web-request-monitoring)

BR,

Peter

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 18, 2024, 9:27am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/10 "2024-10-18T09:27:47Z")

</div>

It says by default it monitors all web request, and I have not disabled it, I am using oneAgent SDK, So do I need to perform something else to make web request monitoring

---

<div class="post-metadata">

**Author:** ![Thomas\_Wirth1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_wirth1/32/1776_2.png) [@Thomas\_Wirth1](https://community.dynatrace.com/u/Thomas_Wirth1)\
**Post date:** [October 18, 2024, 9:33am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/11 "2024-10-18T09:33:22Z")

</div>

The mentioned error message is generated by the Android Gradle plugin, when another plugin or the user tries to use its API after the step is executed. The Dynatrace Android Gradle plugin is using the API from the Android Gradle plugin to include the auto-instrumentation step into the Android app build process. It is using the [android components feature](https://developer.android.com/reference/tools/gradle-api/8.3/com/android/build/api/variant/AndroidComponentsExtension) to interact with the Android Gradle plugin and interacts with it before any action is executed.

It seems there is an incompatibility with your build, because you or a plugin is changing the order in which the project setup is executed. Without any build files, we can’t further troubleshoot your problem. You can create a support ticket and upload your build.gradle files. Then somebody from the support team will assist you in the troubleshooting effort.  
For example, the usage of the Gradle API _evaluationDependsOn_ will change the execution order significantly and therefore the instruction in your Gradle files must be called in the correct order to have a successful build.

You wrote in another message that you tried it with a dummy project. The mentioned API is normally not used in dummy projects. Did you instrument a Flutter or ReactNative app? For these apps, Dynatrace provides the [Dynatrace Flutter plugin](https://pub.dev/packages/dynatrace_flutter_plugin) and the [Dynatrace ReactNative plugin](https://www.npmjs.com/package/@dynatrace/react-native-plugin).

---

<div class="post-metadata">

**Author:** ![Thomas\_Wirth1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_wirth1/32/1776_2.png) [@Thomas\_Wirth1](https://community.dynatrace.com/u/Thomas_Wirth1)\
**Post date:** [October 18, 2024, 9:38am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/12 "2024-10-18T09:38:18Z")

</div>

You have to use the Dynatrace Android Gradle plugin because it adds the auto-instrumentation step to the Android app build.  
When you are using the [standalone manual instrumentation](https://docs.dynatrace.com/docs/platform-modules/digital-experience/mobile-applications/instrument-android-app/instrumentation-via-oneagent-sdk/manual-instrumentation) option, you have to instrument all web requests manually.

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 18, 2024, 9:46am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/13 "2024-10-18T09:46:32Z")

</div>

So when we use OneAgent SDK on android, the web request will not be monitored automatically, it can only be supported by Android Gradle plugin ?

---

<div class="post-metadata">

**Author:** ![Thomas\_Wirth1](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/thomas_wirth1/32/1776_2.png) [@Thomas\_Wirth1](https://community.dynatrace.com/u/Thomas_Wirth1)\
**Post date:** [October 18, 2024, 10:00am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/14 "2024-10-18T10:00:09Z")

</div>

Yes. If you want auto-instrumentation, you have to use the Dynatrace Android Gradle plugin.

---

<div class="post-metadata">

**Author:** ![devggaurav](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@devggaurav](https://community.dynatrace.com/u/devggaurav)\
**Post date:** [October 22, 2024, 8:17am UTC](https://community.dynatrace.com/t/add-dynatrace-gradle-plugin-in-android/48389/15 "2024-10-22T08:17:59Z")

</div>

We can achieve tracking all api’s using one agent sdk as well by creating an interceptor

```auto
class DynatraceInterceptor: Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val uniqueRequestTag = Dynatrace.getRequestTag()
        val timing = Dynatrace.getWebRequestTiming(uniqueRequestTag)
        val newRequest = request.newBuilder()
            .addHeader(Dynatrace.getRequestTagHeader(), uniqueRequestTag)
            .build()

        timing.startWebRequestTiming()
        return try {
            val response = chain.proceed(newRequest)
            timing.stopWebRequestTiming(request.url.toUrl(), response.code, response.message)
            response
        } catch (e: Exception) {
            timing.stopWebRequestTiming(request.url.toUrl(), -1, e.toString())
            e.printStackTrace()
            throw e
        }
    }
}

```

and this inteceptor at your httpClient for android mostly its retrofit

val client = OkHttpClient.Builder()  
.addInterceptor(DynatraceInterceptor())  
.build()

and you can now track all api request without changes and using one agent SDK
