Android Build Systems -Part 1
We all are familiar with build systems in Android, but we still struggle to understand the ABC of it. So, let’s dive into its world and explore it a little bit.
In the context of Android development, a build system refers to a software tool or framework that automates the process of compiling source code, managing dependencies, and packaging resources to create an Android application (APK) file. The build system plays a crucial role in transforming source code and resources into a deployable application.
Let’s learn about one of the popular build tools used nowadays for building Android Application - Gradle (Truly like an elephant)
Gradle is an advanced build automation tool that is widely used in the Android development ecosystem. It is the recommended build system for Android projects. Gradle uses a Groovy or Kotlin-based DSL (Domain-Specific Language) to define build scripts and provides a powerful and flexible framework for building, testing, and packaging Android applications.
Let us break down with a daily life example(not so daily life)…..
Let’s imagine you’re a bike rider, and you want to participate in a race. However, before you can start racing, you need to make sure your bike is in the best condition and ready to perform at its peak. That’s where the build system comes in, acting as your bike mechanic.
In the context of Android development, Gradle is like a skilled bike mechanic who helps you prepare your bike for the race, which in this case is building your Android application handling all the technical aspects of preparing your Android app for deployment. The mechanic ensures that your bike is ready, from the point of arranging and assembling its parts, fine-tuning the gears, adding its required accessories, customising it according to different races, preparing it for races.
Gradle does the same work in building the Android Application…
Below are the few advantages of Gradle
Building Android Applications with Gradle
To build android application, a gradlew
(Gradle Wrapper) is preferred over vanilla Gradle. It is a script that is included in an Android project and used to execute Gradle commands for building and managing the project. It is a wrapper script that provides a convenient way to use Gradle without the need for a separate Gradle installation on each developer's machine.
Gradlew ensures version consistency by automatically downloading the required Gradle version
It simplifies project setup, promotes portability, and provides isolation from system-level Gradle installations, making it easier to collaborate and maintain a consistent build environment.
List of gradlew commands
Below mentioned are few gradlew commands, that are commonly used
Working of Gradle and creation of APK/AAB
Before jumping to working of gradle, let us look into APKs and Bundles(AABs, we will call AABs as bundles).
APKs are self-contained packages that include all the dependencies, resources and code for all possible configurations, while Bundles are publishing formats optimised for dynamic delivery of specific resources and code for the specific device’s configuration.
Bundles provide smaller download sizes and more efficient app installations, especially when distributed through the Google Play Store.
The main difference between an APK and a Bundles lies in their packaging and distribution formats for Android applications.
Creating of APK -
- In the root directory of the project, open the terminal and execute the following command: -
It generates the debug or release variant of the application.
2. Location of APK in the folder structure
app/build/outputs/apk/debug/app-debug.apk— To find the debug apk
app/build/outputs/apk/release/app-release.apk — To find the release apk
Creating on Bundles —
- In the root directory of the project, open the terminal and execute the following command: -
It generates the debug or release variant of the bundles
2. Location of APK in the folder structure
app/build/outputs/bundle/debug/app-debug.aab— To find the debug bundle
app/build/outputs/bundle/release/app-release.aab— To find the release bundle
The generated AAB file can be uploaded to the Google Play Store and APK for specific devices.
Google uses app bundles to generate and serve optimised APKs for each user’s device configuration, so they download only the code and resources they need to run your app. Therefore, users can get smaller and more optimised downloads.
The following are the benefits of Android App Bundle (AAB) over APK on PlayStore:
- Smaller Download Size
- On-Demand App features
- Asset-only modules
Part B extending and explaining few basic gradle commands