Friday, May 18, 2018

The Android build process, Gradle & Android Plugin for Gradle.

Gradle for Android is a build toolkit to automate and manage the build process while it allows to define custom build configurations. Each build configuration can define its own code and resources while certain parts can be reused. The Android Plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to bundling and testing Android apps. Below given overall process in building the Android app module.

1. Compile source to convert to DEX.
2. APK packager combines the DEX and compiled resources into a single APK.
3. The APK packager signs the apk
4. The APK packager uses the zip align tool to optimise the app to use less memory when running on device.

Below are the aspects into the build that can be modified when building with Gradle and the Android plugin for gradle.

1) Build Types : for e.g. release or debug
2) Product Flavors : Different flavours such as paid or free. This can also utilise separate resource and code and reuse common ones that are common across all version of the app/
3) Build variants : this is cross product of build type and product flavour. This is the configuration that gradle uses to build the app. Build variants are not configured explicitly, instead they are formed as a result of defining the build type and product flavor
4) Manifest Entries : One can specify values for some properties of the manifest file in the build variant configuration. These build values override the existing values in the manifest file. This is useful if we want to build multiple APKs for the module that has different application name, min SDK version, or target SDK version.
5) Dependencies : Build system manages dependencies from local file system and remote repositories.
6) Signing : Enables to specify the signing settings in the build configuration The build system by default sign the build with a default key and certificate using known credentials to avoid password prompt during build time. The build sign the release version using release key using the signing configuration specified in the build.
7) Proguard : Build system enables to specify different proguard rules for each build variant. The build system can run Proguard to shrink and obfuscate class files during build process.
8) Multiple APK support: The build system enables to automatically build different APKs that each contain only the code and resources needed for a specific screen density or Application binary interface.


References:
https://developer.android.com/studio/build/

No comments:

Post a Comment