Free Shipping

Secure Payment

easy returns

24/7 support

  • Home
  • Blog
  • Introduction of Gradle in Android

Introduction of Gradle in Android

 July 8  | 0 Comments

Gradle is a build tool with a focus on whole project automation and support for a multi-language development. It was created in 2008.

It was implemented in Java and it is very popular because of its opensource compatibility.

Before we started using Android Studio, we have used Eclipse for Android app development purpose.

The gradle build system is designed to support complex scenarios while creating Android applications like :

  1. Multi-distribution : The application must be customized for multiple clients
  2. Multi-application : Supporting the creation of multiple APKs for different devices while reusing the code.

While running any applicaiton, it triggers the appropriate Gradle task for for that particular application and starts the applicaiton after building of Gradle.

The Android Studio plug-ins allows Gradle tasks to be initiated and managed from within the Android Studio. The Gradle command-line wrapper can be used to build Android Studio based projects.


Example in RealTime

Example : A module within Android Studio project which triggers an intent to load another module in the project. The first module is dependent on the second module since the application will fail to build if the second module cannot be located and launched at runtime.

This dependency can be declared in the file for the first module so the second module is included in the application build.

Other example of dependencies are libraries and JAR files on which the project depends in order to compile and run.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''

Classes & Methods

There are two types of Gradle files in your application : for Project and for particular Module.


buildscript {
    repositories {
    dependencies {
	  //classpath for gradle tools version
        classpath ''
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
allprojects {
    repositories {
task clean(type: Delete) {
    delete rootProject.buildDir


apply plugin: ''
android {
    //SDK Version for compiling the file
    compileSdkVersion 23
    //Building tools version
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId ""
         //minimum SDK Version of app
        minSdkVersion 15
	  //Targeted SDK Version of app
        targetSdkVersion 23
         //version code of app
        versionCode 1
         //version name of app
        versionName "1.0"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
//dependencies which are using for compiling libraries and other things used for testing and library support
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''
settings.gradle(Project Setttings)
include ':app'

Shortcut for Update Gradle

If you update any gradle files, it is recommended to sync project with Gradle file option.



Another functionality of Gradle is that of dependencies.

You can add library files and compile them for dependencies. Here the compile of testing number has been given to junit version name as ‘junit:junit:4.12’. You can compile your project applicaiton using v4 and v7 with their verisons.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''

Adding Project Dependencies

1. If you want to use user interface to fill out the dependcies, you can choose do the following :

a) Right click on the module(app)

b) Choose Open Module Settings


2. The Dialog Box will open as below:


3. Choose Dependenices Tab from above Tabs.


4. Now to add a dependencies, Simply click on + Button.


5. Let’s click on any dependency you want to add dependency. For example, here I am adding Joda Time dependency.


6. If you click on OK the dependency will be added like below:

dependencies {
 compile fileTree(dir: ‘libs’, include: [‘*.jar’])
 compile ‘’
 compile ‘joda-time:joda-time:2.3’

Note : Remember to always Sync Project with Gradle Files to kick off the build.

Support libraries : v4 and v7

V4 library : This library is designed to be used with Android 1.6 and higher. It includes the largest set of APIs compared to the other libraries, including support for application components, user interface features, accessibility, data handling, network connectivity, and programming utilities.

App Components :

  1. Fragments
  2. NotificationCompat
  3. LocalBroadcastManager

V7 library : There are several libraries designed to be used with Android 2.1 and higher. These libraries provide specific feature sets and can be included in your application independently from others.

App Components :

  1. ActionBar
  2. AppCompatActivity
  3. AppCompatDialog
  4. ShareActionProvider


For the most part, Android Studio performs application builds in the background without any intervention from the developers. This build process is handled using the Gradle system, an automated build toolkit designed to allow the ways in which projects are build to be configured and managed through a set of build configuration files.

Gradle builds system and configuration files within the context of an Android Studio project.

Keep visiting our site for more updates on Android and other technologies.

Hope this blog was informative enough on the Introduction to Gradle in Android.