![]() |
VOOZH | about |
Gradle is a build system (open source) that is used to automate building, testing, deployment, etc. "build.gradle" are script where one can automate the tasks. For example, the simple task of copying some files from one directory to another can be performed by the Gradle build script before the actual build process happens.
Every Android project needs a Gradle for generating an apk from the .java and .xml files in the project. Simply put, a Gradle takes all the source files (java and XML) and applies appropriate tools, e.g., converts the java files into dex files and compresses all of them into a single file known as apk that is actually used. There are two types of build.gradle scripts
Top-level build.gradle:
It is located in the root project directory and its main function is to define the build configurations that will be applied to all the modules in the project. It is implemented as:
The top-level build.gradle supports various build configurations like:
buildscript: This block is used to configure the repositories and dependencies for Gradle.
Note: Don't include dependencies here. (those will be included in the module-level build.gradle)
dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project.
This line adds the plugins as a classpath dependency for gradle 3.0.1.
Module-level build.gradle:
Located in the project/module directory of the project this Gradle script is where all the dependencies are defined and where the SDK versions are declared. This script has many functions in the project which include additional build types and override settings in the main/app manifest or top-level build.gradle file. It is implemented as:
The Module-level build.gradle supports various build configurations like:
Both the top-level and module-level build.gradle files are the main script files for automating the tasks in an android project and are used by Gradle for generating the APK from the source files.