Whenever you create a project in Android Studio, the build system automatically generates all the necessary Gradle build files.
Gradle Build Files
- Gradle build files use a Domain Specific Language or DSL to define custom build logic and to interact with the Android-specific elements of the Android plugin for Gradle.
- Android Studio projects consist of one or more modules, which are components that you can build, test, and debug independently. Each module has its own build file, so every Android Studio project contains two kinds of Gradle build files:
- Top-Level Build File: This is where you’ll find the configuration options that are common to all the modules that make up your project.
- Module-Level Build File: Each module has its own Gradle build file that contains module-specific build settings. You’ll spend most of your time editing module-level build file(s) rather than your project’s top-level build file.
- To take a look at these build.gradle files, open Android Studio’s Project panel (by selecting the Project tab) and expand the Gradle Scripts folder. The first two items in the Gradle Scripts folder are the project-level and module-level Gradle build files
Top-Level Gradle Build File
Every Android Studio project contains a single, top-level Gradle build file. This build.gradle file is the first item that appears in the Gradle Scripts folder and is clearly marked Project.
Most of the time, you won’t need to make any changes to this file, but it’s still useful to understand its contents and the role it plays within your project.
Module-Level Gradle Build Files
In addition to the project-level Gradle build file, each module has a Gradle build file of its own. Below is an annotated version of a basic, module-level Gradle build file.
Other Gradle Files
In addition to the build.gradle files, your Gradle Scripts folder contains some other Gradle files. Most of the time you won’t have to manually edit these files as they’ll update automatically when you make any relevant changes to your project. However, it’s a good idea to understand the role these files play within your project.
gradle-wrapper.properties (Gradle Version)
This file allows other people to build your code, even if they don’t have Gradle installed on their machine. This file checks whether the correct version of Gradle is installed and downloads the necessary version if necessary.
This file references all the modules that make up your project.
gradle.properties (Project Properties)
This file contains configuration information for your entire project. It’s empty by default, but you can apply a wide range of properties to your project by adding them to this file.
local.properties (SDK Location)
This file tells the Android Gradle plugin where it can find your Android SDK installation.
Note that local.properties contains information that’s specific to the local installation of the Android SDK. This means that you shouldn’t keep this file under source control.