5 Tips to Speed Up Gradle Build in Android Studio

Before Android Studio, most of the developers didn’t know how to build Android APK without Eclipse. They could do this on the command line but learning each (dx, aapt, etc) tool and their role in SDK is not everyone’s cup of tea.

Gradle is a build system that automatically takes all the source file (like Java, XML, HTML, etc), uses required tools (for ex – converting .class files to dex files), compresses them and group all of them in one file called Android Package Kit or APK.

There are multiple advantages to this Gradle build system in Android Studio. It doesn’t only save us from involving in such low-level developments but as Gradle is a JVM based build system, it also allows you to write your own script in Java.

Though Gradle has improved a lot with the updates released in recent years, it’s still not up to the mark. If you are an Android developer, you are definitely wasting a lot of time waiting to finish the Gradle build process. Yes, I know Processor and RAM plays an important role in this regard, but the problem still remains the same.

Today, I am going to share some tips that you can use to speed up the Gradle build process. So, let’s get started..!!

Also Read: Why Kotlin is Better than Java for Android App Development?

Speed Up Gradle Build in Android Studio

1. Use the Latest Version of Gradle Plugin

Google improves the performance of the Gradle build system version by version. So, it’s always recommended to use the latest one.

The current version is 5.2 which comes with improved C++ plugins, new C++ project types for Gradle init, service injection into plugins and project extensions, Kotlin DSL 1.1.3 and more. This latest version of the plugin can speed up the Gradle build process up to 25%.

2. Disable Multiple APK Creations

speed up gradle in android studio

Android studio has many useful options that can make our work super easy. However, using them always is not recommended. If you are using splits block to create multiple APKs for different devices, it’s time to disable that.

You may use it to reduce app size in the release but disabling it during development can reduce Gradle build time by 10%.

3. Include Minimal Resources

Android Studio allows you to add any number of required resources to the project. You can even build an application that supports multiple languages and different screen sizes. But, what’s the point in adding everything at the beginning? You should always add minimal resources while development. It will help in reducing Gradle build time.

You can use the following code for it.

productFlavors{
development{
minSdkVersion 21
resConfigs ("en","xxhdpi")
...
}
}

Recommended: Free Android development Resources on the Internet

4. Enable Gradle Caching

Caching improves the performance in every case and so in Android studio. After enabling caching in Gradle, it will start caching the task outputs from previous builds and location and ultimately reduce the Gradle build timing.

You can enable Gradle caching by adding the following code in your gradle.properties file.

set org.gradle.caching= true

5. Avoid Legacy Multidex when using Command line

speed up gradle in android studio

If you are developing your app with minSdkVersion < 21, you might be using Legacy Multidex. Android Studio required you to use Multidex when an app exceeds 64K method reference limits, but it also makes the Grade build slow.

If you are using the command line to build your app, consider working with minSdkVersion 21 or more. This will significantly speed up the Gradle build process.

Conclusion: Speed Up Gradle Build in Android Studio

These are some of the tips to speed up Gradle build in Android Studio. Also, if you are using a laptop has less than 8GB RAM, it’s time to upgrade now. I hope that Google will focus on speeding up Gradle build to make Android app development more smoother.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.