Appendix B. Gradle Basics

The recipes in this book are for the Gradle build files inside of Android. Gradle is a powerful build tool, however, which is used extensively in other projects. This appendix reviews the basics of Gradle. All capabilities reviewed here can be used inside Android build files as well.

Installing Gradle

Note

You do not need to install Gradle to use it in Android projects. Android Studio includes Gradle, and provides a Gradle wrapper as well. Its use is demonstrated in Recipe 4.1, among other recipes.

Gradle comes as a single, ZIP download. You merely need to download the latest distribution from the Gradle website to get started. Installation is as easy as:

  1. Download and unzip the distribution

  2. Set a GRADLE_HOME environment variable to point to the unzipped folder

  3. Add the bin folder under GRADLE_HOME to your path

The gradle command can then be executed at the root of any project. By default the build file is called build.gradle, but any name can be used. The -b or --build-file flag is used to specify a different build file.

As an alternative, Gradle provides a wrapper, which can be used to automatically download and install Gradle on its first use. The wrapper is demonstrated later in this appendix.

Note that though Gradle build files are written in Groovy, you don’t need to install Groovy to run Gradle. Gradle includes a distribution of Groovy inside it, which is used to power the build.

To see the details of the Gradle installation, run Gradle ...

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.