Select Page

Gradle is the build system that takes the best features from other build systems (Ant & Maven) and combines them into one. It is a plugin based system.

Gradle-elephant

It builds APK by using all the source files, then applies the appropriate tool (java class into dex file), and group them into a single unit.

Gradle simplifies the following process :

  • Build different flavours or variants of your app
  • Make simple script-like tasks
  • Manage and download dependencies
  • Keystore customization

A Gradle project describes its build in a file called build.gradle located in the root folder of the project. The following snippet shows the simple build file.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:2.2.0’
}
}
apply plugin: ‘com.android.application’
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "ur app ID"
minSdkVersion 16
targetSdkVersion 23
versionCode 1600010100
versionName "1.1.0-alpha"
}
}

Android build file contains the following 3 main parts

1. buildscript {…}

This block is where you configure the repositories and dependencies for Gradle itself.

repositories {}

This block configures the repositories Gradle uses to search or download the dependencies. Gradle pre-configures support for remote repositories such as JCenter, Maven Central, and Ivy.

dependencies {}

This block configures the dependencies Gradle needs to use to build your project.

2. apply plugin :

       com.android.application : This is the plugin used for building Android applications.

       com.android.library : This is the plugin used for building Android Library.

3. Android configuration :

This is the entry point for the Android DSL (Domain Specific Language). Here you need to configure all the following parameters for the android build:

compileSdkVersion : It specifies the Android API level, Gradle should use to compile your app.

buildToolsVersion : It specifies the version of the SDK build tools.

applicationId : Uniquely identifies the package for publishing.

minSdkVersion : Minimum API level required to run the app.

targetSdkVersion : The API level used to test the app.

versionCode : The version number of your app.

versionName : The version name for your app.

 

 

Elsewhere

Jaison Fernando

Android Developer at NFN Labs
Elsewhere