Table of Contents

Android Gradle

Briefly,Android Gradle is a new build system,and we can assume it is used to replace the ant build system.From the Google official post,it can be integrated with the IDE easily,such as Android Studio. And the Gradle script is written with Groovy(Groovy_(programming_language)).

Also it will provide a flexible way for customization, for different product but the same source codebase, for different build(debug,release,buildType,Product flavor),and of course it support obfuscates the source code with proguard.

Anyway,I hope it will be continuely improved,developed,and driven by Google.

What's Gradle

Gradle:http://www.gradle.org/

Gradle is build automation evolved. Gradle can automate the 
building, testing, publishing, deployment and more of software packages or other types of projects such as 
generated static websites, generated documentation or indeed anything else.

Install Gradle

Download Gradle

http://www.gradle.org/downloads

Setup Gradle PATH

set the gradle/bin to system PATH.

export PATH=${PATH}:/Users/pengjianqing/Documents/Android/gradle-1.6/bin 

First run Gradle

when first time run gradle tasks,it will start some install automatically.

Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.4/gradle-0.4.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/gradle-model/0.4/gradle-model-0.4.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.4/builder-0.4.pom
Download http://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/4.9/proguard-gradle-4.9.pom
Download http://repo1.maven.org/maven2/net/sf/proguard/proguard-parent/4.9/proguard-parent-4.9.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.4/builder-model-0.4.pom
Download http://repo1.maven.org/maven2/com/android/tools/sdklib/22.0/sdklib-22.0.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.4/builder-test-api-0.4.pom
Download http://repo1.maven.org/maven2/com/android/tools/sdk-common/22.0/sdk-common-22.0.pom
Download http://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/22.0/ddmlib-22.0.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/22.0/manifest-merger-22.0.pom
Download http://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.pom
Download http://repo1.maven.org/maven2/net/sf/proguard/proguard-base/4.9/proguard-base-4.9.pom
Download http://repo1.maven.org/maven2/com/android/tools/common/22.0/common-22.0.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1.1/httpcomponents-client-4.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/project/4.1.1/project-4.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1/httpcomponents-client-4.1.pom
Download http://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/22.0/layoutlib-api-22.0.pom
Download http://repo1.maven.org/maven2/com/android/tools/dvlib/22.0/dvlib-22.0.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/11/commons-parent-11.pom
Download http://repo1.maven.org/maven2/org/apache/apache/4/apache-4.pom
Download http://repo1.maven.org/maven2/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.pom
Download http://repo1.maven.org/maven2/kxml2/kxml2/2.3.0/kxml2-2.3.0.pom
Download http://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.pom
Download http://repo1.maven.org/maven2/com/google/guava/guava/13.0.1/guava-13.0.1.pom
Download http://repo1.maven.org/maven2/com/google/guava/guava-parent/13.0.1/guava-parent-13.0.1.pom
Download http://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/7/oss-parent-7.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.1/httpcomponents-core-4.1.pom
Download http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/5/commons-parent-5.pom
Download http://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom
Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.4/gradle-0.4.jar
Download http://repo1.maven.org/maven2/com/google/guava/guava/13.0.1/guava-13.0.1.jar
Download http://repo1.maven.org/maven2/com/android/tools/common/22.0/common-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.4/builder-model-0.4.jar
Download http://repo1.maven.org/maven2/com/android/tools/build/gradle-model/0.4/gradle-model-0.4.jar
Download http://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar
Download http://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar
Download http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
Download http://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.jar
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.jar
Download http://repo1.maven.org/maven2/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/22.0/layoutlib-api-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/dvlib/22.0/dvlib-22.0.jar
Download http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/sdklib/22.0/sdklib-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/22.0/ddmlib-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.4/builder-test-api-0.4.jar
Download http://repo1.maven.org/maven2/com/android/tools/sdk-common/22.0/sdk-common-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/22.0/manifest-merger-22.0.jar
Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.4/builder-0.4.jar
Download http://repo1.maven.org/maven2/net/sf/proguard/proguard-base/4.9/proguard-base-4.9.jar
Download http://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/4.9/proguard-gradle-4.9.jar
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.

Android Gradle user guide

Gradle Plugin User Guide:http://tools.android.com/tech-docs/new-build-system/user-guide

Gradle is an advanced build system as well as an advanced build toolkit allowing to create custom build logic through plugins.

Here are some of its features that made us choose Gradle:

Gradle command

Gradle Command Line :http://www.gradle.org/docs/current/userguide/gradle_command_line.html

What's Groovy

Groovy:http://groovy.codehaus.org/

Groovy_(programming_language)

Groovy...
  * is an agile and dynamic language for the Java Virtual Machine
  * builds upon the strengths of Java but has additional power features inspired by languages like Python, Ruby and Smalltalk
  * makes modern programming features available to Java developers with almost-zero learning curve
  * provides the ability to statically type check and statically compile your code for robustness and performance
  * supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain
  * makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
  * increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications
  * simplifies testing by supporting unit testing and mocking out-of-the-box
  * seamlessly integrates with all existing Java classes and libraries
  * compiles straight to Java bytecode so you can use it anywhere you can use Java

Gradle build script example

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}

apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar',
     'libs/webimageloader-1.1.4.jar',
     'libs/square-otto-1.3.2.jar',
     'libs/libGoogleAnalyticsV2.jar',
     'libs/android-support-v4.jar',
     'libs/androidannotations-api-2.7.jar',
     'libs/disklrucache-1.3.1.jar'
     )
}

android {
    compileSdkVersion 17
    buildToolsVersion "17"


    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 17
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src','.apt_generated']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
    }

    signingConfigs {
        debug {
            storeFile file("proguard/debug.keystore")
        }

        releaseConfig{
            storeFile file("proguard/XXXXX.keystore")
            storePassword "XXXX"
            keyAlias "XXXX"
            keyPassword "XXXX"
        }
    }

    buildTypes {
        release {
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            signingConfig signingConfigs.releaseConfig
        }
    }
}

Basic Usage

gradle assemble