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

Can I instrument Android app bundles with the manual method?

alejandro_herna
Organizer

The documentation states that It's not possible to instrument Android app bundles with Android Gradle plugin and command line instrumentation methods, however there's a manual method:
https://www.dynatrace.com/support/help/user-experi...
Can I instrument Android App bundles with the manual method?
If not, is Dynatrace working on it so it can be supported? is there a date?


11 REPLIES 11

paul_schlagitwe
Dynatrace Participant
Dynatrace Participant

Hi @alejandro h.,

Yes you can use manual instrumentation for Android App Bundles.
Just add the following to the dependencies-block in your base modules build.gradle:

api 'com.dynatrace.agent:agent-android:7.1+'

If you correctly set up your application - meaning that all feature modules have a dependency to the base module - then you should be able to do Dynatrace API calls from everywhere.

Make sure to insert the Dynatrace.startup(...) somewhere in the base module. Preferably in the onCreate method of your main activity.

For more on manual instrumentation please follow the documentation.

Regarding Auto-Instrumentation via command line or the Dynatrace Gradle Plugin:
Right now Android App Bundles and Instant Apps are not supported!
However there are efforts to support both in the future but for now the only way is to manually instrument.
And no, there is no date yet, all I can say is that the upcoming version 7.2 will still lack support for that.

Best regards,
Paul


Thank you @Paul S.


May I know Where is the documentation of the API method calls?


mobileappsuppor
Newcomer

I'm using Dynatrace and wish to only have it applied for development flavour using product flavours(i have created 2 flavours in app development/production) in gradle: if possible please let me know how to setup the gradle file for auto instrument using product flavors in Android.

productFlavors
{development {

    }
production {
}
}

looking forward to hearing from you.

By default the dynatrace plugin is applied to all flavors. If you want to have different configurations for your flavors you can use something like:

android{

productFlavors {
production{
...
}
development{
...
}
}
}
...
dynatrace {
defaultConfig { // applies to all flavors except for those defined below
applicationId '<DEV_ApplicationID>'
beaconURL '<ProvidedBeaconURL>'
}

productFlavors {
production{ // name of your flavor
applicationId '<PROD_ApplicationID>'
beaconURL '<ProvidedBeaconURL>'
}
}
}

If you only define one flavor the configuration for all other flavors falls back to the defaultConfig which cannot be omitted in this case.
Unfortunately its not yet possible to have the instrumentation for one flavor and do not instrument another flavor.
However there is a workaround for that. In this case you would have to define a property (ie "instrument") and if you pass this property to your gradle task (ie: gradlew assembleRelease -Pinstrument) then the plugin is applied and the build is instrumented.
In your gradle file you have to define an if condition:

<code>if(project.hasProperty('instrument')) {
apply plugin: 'com.dynatrace.tools.android'
dynatrace {
defaultConfig {
applicationId '<YourApplicationID>'
beaconURL '<ProvidedBeaconURL>'
}
}
}<br>

Thats not very pleasant but improvement is on the way. There will be a new major version of the dynatrace plugin in a few months that will have a much better support for usecases like that.


Hi @Paul S.
Thanks for instant reply i have applied your workaround(had set property in gradle and run(ie: gradlew assembleRelease -Pinstrument) then the plugin is applied and the build is not instrumented) getting auto instrument failed (No java found) ,although system already has installed java path to environment variables(system variables).
also dynatrace log is not being generated.

Looking forward for a solution earliest.

Thanks!


@Mobileapp S.
Did it work previously? Before you applied the workaround?
What agent version are you using? Latest is 7.2.4.
The auto-instrumentor requires a JDK (not JRE!) with version 1.8 or higher.
Before you run "gradlew ..." in your terminal, can you verify the output of "echo %JAVA_HOME%" (if you are on windows, otherwise: "echo $JAVA_HOME").
The path should point to your java JDK installation.


@Paul S.
Yes previously it was instrument and yes i am using latest version 7.2.4 and java version 1.8 version.

"echo %JAVA_HOME% pointed to java installation path(C:\Program Files\Java\jdk1.8.0_172)


Can you also verify if the following file exists: %JAVA_HOME%\bin\jar
If not, its not a JDK but a JRE (despite the name jdk1.8.0)

If it does exist we need to dig deeper and I need to take a look at your build.gradle file.
Can you open a support ticket?


@Paul S.
%JAVA_HOME%\bin\jar
Yes it exists there, please find the attach screenshot.

Todays is our release plan looking forawrd to a earlist response.


That looks fine.
Can you open a support ticket and provide your build.gradle file along with the exact error message you receive when you type the "gradlew assembleRelease -pInstrument" (or replace "assembleRelease" with whatever buildtype you want to build")