How to Mitigate Slow Build Times While Using Firebase Performance Plugin

I recently added Firebase Performance Plugin to one of my projects and experienced a drastic increase in the build time of the app. The app initially used to build in under 20 seconds and with the addition of this plugin, it started taking around 5–6 minutes for a single build. This was quite annoying and I looked for what might be causing the increase in build times.

If you look closely you will find out that the following task is taking too long to build:

app:transformClassesWithFirebasePerformancePluginForDebug

There is a post-compilation phase when using Firebase Performance on Android that results in slow build times.

How to Mitigate the Issue

The fix that applied only mitigates the issue by adding a parameter to build command so that this plugin can be disabled during development.

In root/buildscript/dependencies wrap the plugin classpath inside the following if condition.

if (!project.hasProperty("disable-performance-plugin")) {
    classpath('com.google.firebase:firebase-plugins:1.1.5') {
        exclude group: 'com.google.guava', module: 'guava-jdk5'
    }
}

Excluding com.google.guava depends on whether it is causing conflicts with your Guava dependencies as mentioned in the getting started documentation.

Next, in app/build.gradle wrap the apply plugin code in the following condition.

if (!project.hasProperty("disable-performance-plugin")) { 
    apply plugin: 'com.google.firebase.firebase-perf' 
}

Now, simply build using the command line with the parameter for disabling the plugin.

./gradlew your-task -Pdisable-performance-plugin

If you use Android Studio for building the project then you add the same config in Compiler settings of Studio. Set the command line options to:

-Pdisable-performance-plugin

That’s it. Adding this parameter should make your life easier! :)

Credits to Ivan Kravchenko for the original answer on Stack Overflow.

You can buy me a coffee if this post really helped you learn something or fix a nagging issue!


Written on June 14, 2018 by Vivek Maskara.

Originally published on Medium

Vivek Maskara
Vivek Maskara
SDE @ Remitly

SDE @ Remitly | Graduated from MS CS @ ASU | Ex-Morgan, Amazon, Zeta

Related