Dynatrace is exploding your Android build time- here’s how to fix it

Ruby López
Tekton Labs
Published in
2 min readFeb 25, 2019
You, waiting forever…

Dynatrace is a very powerful application monitoring tool that you can add to your mobile application, web service (and much more) to help you find and resolve performance problems even before users discover them.

We have implemented it in a project I’m working on and it is pretty easy to add. However, after adding it, our development team noticed that our building time increased drastically.

Why does it affect building time?

Dynatrace Gradle plugin auto-instruments your Android app on every build. That means that every time you create an apk, Dynatrace will decompress your apk, modify it, and compress it again. And that results in:

Gradle Build Running …

Don’t forget about Instant Run

According to Dynatrace’s documentation, you can’t use the Android Studio feature Instant Run. Yup, no more fast pushes of your code changes (which means more time wasted trying to develop your app).

But don’t worry. There is a simple solution for you.

The solution

Assuming you have a simple configuration of Dynatrace in your app/build.gradle like in the following case (where {NameIdForYourApp} and {nameOfYourApp} vary according to your Dynatrace information):

apply plugin: ‘com.dynatrace.tools.android’
dynatrace {
defaultConfig {
applicationId ‘{NameIdForYourApp}’
startupPath ‘https://dynamonitor.{nameOfYourApp}.net/'
agentProperties ‘DTXSendEmptyAutoAction’: ‘true’, ‘DTXLogLevel’: ‘debug’
}
}

You must replace the “apply” and “dynatrace” part so the final gradle looks like this:

Notice the if (project.gradle.startParameter.taskNames.any { it.toLowerCase().containts('release') }) . This line detects if the current build will have a release build type and will add the final dynatrace configuration part only in the case of releasing it.

And… that’s it. One more line and you’ll see the difference.

Does this really work?

Here you can see the differences in compilation time. Before and after adding the changes to my gradle file.

Building times before and after changes in gradle

As you can see, the building time in the debug case has been reduced drastically. The time for the release building time increased a bit though. It could be caused by the additional task of modifying the gradle.

That being said, the important part is in debug, where we spend most of our time while trying to create and improve our features. The average debug building time decreased by more than 80%! (That’s a lot if you ask me).

That’s it! I hope this may help some people who have also encountered this problem. Thanks for reading~ 😊.

Powered by Tekton Labs

--

--

Ruby López
Tekton Labs

Android Tech Leader at TektonLabs Peru. Likes learning, watching animes and pamper her kitty.