An advance build toolkit Gradle in Android Part-1
Most of the time we don’t care about the Gradle files. We only add dependencies, modify target and minimum API levels, signing configuration or build types. For complicated thing we just end up copy-pasting mysterious snippets from some website, without understanding how actually they work. So this is the post to understand very basic level of Gradle configuration for a single Android project.
What is build tool?
Build tools are programs that automates and manage the build process like creation of executable applications from source code (.apk), linking and downloading the resources etc.
In other words build automation is the act of scripting or automating a wide variety of tasks like
- Compiling source code into binary code
- Downloading dependencies
- Packaging the binary code
- Execute test cases
Available build tools
There are various popular build tools available. Some of them are as follows-
Ant, Maven, Gradle, MSBuild, Rake, NAnt etc.
You can find more details here.
How to use?
Android studio wraps the Gradle runtime, hence no additional installation is required so when you create a new project in Android studio, the Gradle build scripts are automatically created and when you run application, Android Studio triggers the corresponding Gradle task.
You can also use a wrapper script created by Gradle. This allows you to run a Gradle build without required any additional installation from the command line.
Gradle command line
To run Gradle from the command line you must have installed Gradle or you use the Gradle wrapper (gradlew) to execute the build. The wrapper downloads Gradle if necessary. Gradle can run multiple tasks with a single command by providing the names of all the tasks to run. The names of the tasks to run should be separated by a space. Below are the some of the common tasks-
Build project (assemble and check task both)
Clean and build project
Clean and build project
./gradlew clean build
Run test cases
To see all available tasks, use the command-
Gradle Settings File
The settings.gradle file, located in the root project directory. Here you can define which modules to include when building your app like-
Top (project) level build file
The top-level build.gradle file, located in the root project directory, defines build configurations that apply to all modules in your project.
Module level Build File
The module-level build.gradle file, located in each project/module/ directory. It allows you to customize your build configuration for the specific module.
Properties are a valuable tool for easily customizing Gradle builds and its environment. Gradle has two properties files, located in your root project directory.
Here you can configure project-wide Gradle settings like Gradle daemon's maximum heap size.
Configures local environment properties for the build system, such as the path to the SDK or NDK installation.
This article is more focused on basic understanding of Gradle. You can also refer Android official site for more details. I will soon come up with more customizable build configuration feature. So stay tune with me.
To find more interesting topics on Software development follow me at https://firstname.lastname@example.org