Optimizing for Performance with Gradle in Android Studio

Optimizing for Performance with Gradle in Android Studio

Having been and android developer for a couple of years now, i have had the priviledge to transition between:

not using Gradle >to> Seeing it introduced and complaining about Gradle>> To accepting my fate that it was not going anywhere>> to learning how to make it work for me.

Biggest complaint when using Gradle: It takes time. Here is why: By default Gradle will only run one task at a time, regardless of the project structure.

Yeah that sucks!

How do we make it work well: Enabling it to run parallel.

What this means is that Gradle can run multiple tasks at the same time therefore executing independent subprojects.

This doesn't come by defaut in Android studio: To build a projects in parallel mode you can do this in two ways(either works):

  1. Enable it in a project: this will make gradle builds to happen in parallel by default for the specific project. Add the following line as a setting to the project’s gradle.properties file:
org.gradle.parallel=true
  1. Default for android studio: You probably do not have this file if you are reading this(Or maybe you do) - gradle.properties located in the .gradle folder. On windows this will be:

    C:\Users\<yourUserName>\.gradle If you do not have it:

  2. Create a : Use any text editor

  3. Paste the following lines inside it:
org.gradle.parallel=true
org.gradle.daemon=true
  1. Save the file as gradle.properties

the lines org.gradle.daemon turn on daemon so that every time we build the application, it doesn’t need to rerun the entire Gradle application every time.

Restart Android studio. Enjoy

Photo by Ahmad Odeh on Unsplash