cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

Android - Setting Server URL in code when using gradle plugin

kristof_renders
Dynatrace Pro
Dynatrace Pro

Hi,

I have a customer that is using the gradle plugin to instrument their application.

In their app, they currently change dynamically the environment (prod/uat/...) which would mean the data will have to be sent back to a different dynaTraceMonitor url.

If they try to change the environment once the app has been launched, this does not point to the new server. Is this approach possible?

Alternatively they would do all instrumentation directly in the code, losing the flexibility.

KR,
Kristof

2 REPLIES 2

Thomas_Wirth1
Dynatrace Pro
Dynatrace Pro

The Dynatrace Gradle plugin uses the auto-instrumentor to instrument the application. The auto-instrumentor injects the agent startup into the application startup sequence. This injection feature can't be deactivated.

The Android Gradle plugin has a feature called product flavor, where you can build different APKs from the same project. The Dynatrace Gradle plugin support this features and allows you to configure different AppMon servers for each APK. In your case you would have a PROD app/apk and an UAT app/apk. The product feature also allows the customer to reduce the size of the PROD app, because code/features for other environment should not be part of the prod APK.

If the customer does not want to generate multiple APKs, the only workaround is to restart the agent (shutdown + startup call). The agent does not support fast restarts and should not be restarted in the Application.onCreate method. The agent also ignores multiple startup calls and therefore a small sleep interval should be placed between shutdown and startup. Keep in mind that the startup call blocks the current thread and the agent startup sequence is delayed, when the agent shutdown sequence is not finished. This workaround is not ideal and therefore we would not recommend it.

If this feature is important for the customer, then you should generate a RFE.

Thank you Thomas, for your reply.

I - and the customer - was aware about the product flavor. However that would mean having multiple APKs and they did not want that.

I will suggest them to use the stop/start way - even if it is not recommended.

Thanks again!