What is Gradle?

While some of you may know Gradle (or Maven or Ant) from other projects, for Android developers its of great importance to understand and utilize Gradle to its fullest. Gradle ensures your builds run as consistently as possible across multiple devices while empowering you to dynamically change and easily update the core requirements of your application.

Its like a recipe

Take a standard recipe, like this awesome chocolate cake – it contains a description of all the parts and instructions required to make it. For starters, you need flour, sugar, oil, and a bunch of other things. These are the Gradle dependencies. You also need a bunch of tools like a bowl, mixer, and measuring instruments. These are the Gradle plugins. Where do you get all this stuff? Probably your pantry or the grocery store; these are Gradle (Maven) repositories.

Now that you've collected all of your tools and ingredients, you'll need to follow the instructions to actually make the cake. For Android developers this means configuring the android object, telling it how you want the app built. configurationsbuildscript, and many others also provide instructions.

Finally, you've completed the instructions for sifting, whisking, and folding. Now its time to bake this cake! In our analogy gradle or gradlew executable is the oven. You pass in your build.gradle file and it bakes you an APK.

While many stop here, often recipes leave room for interpretation to make it your own. This is where Gradle really shines. You can inject your own ingredients (dependencies), tools (plugins), and instructions (additional code.) Just like modifying a cake, this could change the entire process. Maybe it takes longer to bake (slower build times) or it outputs multiple cakes (like a magical cake copy machine.)

This is just the beginning

After you build a project or two you'll find that many open source projects and tools utilize Gradle. It could be generating more code, archiving artifacts, counting the methods in your app, running adb commands, or even sending a message to your group chat when its done.

Faster Android builds

The bigger your app and team get, the slower your build will inevitably become. Here are a few tips to get you building faster. This guide is geared towards anyone responsible for buying machines for Android developers and focuses on rapid iteration.

Raw power

This is your profession, invest in decent tools. While its true that some famous musicians still play cheap guitars, this really doesn't translate to technology. Aim for these specs.

  1. In a desktop, shoot for as many processing cores as you can afford. 6-8 hyper threaded cores beats 4 cores at a higher clock speed. This means an i7 or Xeon desktop like the Dell Precision 7000 or the MacPro.
  2. In a laptop, portability is nice, but often leads to low power processors. i7 is required and avoid anything ending in U, like the i7-5557U found in 13" Macbook Pro. The Dell XPS i7 15" or the 15" Macbook Pro will keep you building fast on the go.
  3. 16Gb RAM minimum. Everything Android related is a memory hog and gets faster the more memory you can give it.
  4. SSD is required. The faster you get files from one place to another, the faster you build and deploy.


Setting up your project correctly can really make a difference.

  1. Break your app into modules. This means properly decoupling chunks of your app into several standalone pieces. These can be built in parallel and even cached. Should your work be isolated to a single module, this will certainly speed things up.
  2. Carefully consider Gradle plugins and annotation processors. These could be slowing down builds because they are figuring stuff out when you build. Obvious but often overlooked.
  3. Configure your build.gradle to exclude things you don't need during rapid development. This cut off between 10%-30% build time in my experience.
  4. Avoid MultiDex if possible.

Gradle configuration

Gradle can be a blessing or a curse and you need to configure it to work optimally. After applying these settings my medium sized project build times went from 37s to 20s (clean assembleDebug)!

To get started, locate your gradle.properties file:

  • Linux: /home/<username>/.gradle/
  • Mac: /Users/<username>/.gradle/
  • Windows: C:\Users\<username>\.gradle

Next add the following lines to gradle.properties:

org.gradle.jvmargs=-Xms256m -Xmx3072m

Lastly edit your build.gradle. Below is a starting point and according to the docs, there is a formula to adhere to. From experience you need to try out different settings to ensure you aren't negatively impacting your build times.

android {
  dexOptions {
    maxProcessCount 4
    javaMaxHeapSize "2g"