Chapter 6. Performance and Documentation

6.1 Performance Recommendations


You need to improve the performance of your Gradle build.


Use a combination of the techniques recommended here.


First things first: these are not recommendations that will affect the performance of your app. There are many things you can do to help your app, many of which involve the ProGuard tool that comes with Android. This section is not about that—it’s about improving the performance of the build itself.

This recipe discusses settings that can be added to the file in the root of the Android application. If you prefer to use global settings, add a file called to the .gradle subfolder in your home directory.

The Gradle daemon

The Gradle daemon is a background process that stays alive between builds, caching both data and code. Most recent versions of Gradle automatically start a Gradle daemon whenever you run from the command prompt.

By default, Android Studio starts a Gradle daemon in your project, with a timeout period of three hours, which is long enough for most development tasks. If you run Gradle from the command line, however, you may not automatically start the daemon.

To make sure the daemon starts, add the setting shown in Example 6-1.

Example 6-1. Gradle daemon setting in

The daemon can also be started and stopped using a command-line flag. Use --daemon and --no-daemon to enable or ...

Get Gradle Recipes for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.