Getting started with the new Android build system

As many of you might be aware, the Android Development Tools team is working on a brand new build system. The new system has been in development for a while now, but is being officially announced at Google I/O 2013. The updated build system does away with Ant and moves to the Gradle build automation tool. You can read more about Gradle at gradle.org. The new Android build system is documented on the Android Developer Tools site at tools.android.com.

Getting started with the new build system is relatively easy. To get started you’ll need to make sure you have both Maven and Gradle installed.

Install Homebrew

If you’re working on OS X you can make your life a whole lot easier by installing Homebrew. If you don’t already have it installed, you can install it by running the following command from your terminal:

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Install Maven

    $ brew install maven

Install Gradle

As of May, 2013, the new Android build system only supports Gradle versions 1.3/1.4. This means it won’t work with the latest version of Gradle. You’ll have to follow the instructions at gradle.org/installation to install a prior version of Gradle. Otherwise you could simply install the latest version using Homebrew.

    $ brew install gradle

You can verify you have the correct version of Gradle installed using the following command:

    $ gradle -v

You should see output that looks something like this:

 
    ------------------------------------------------------------
    Gradle 1.3
    ------------------------------------------------------------
 
    Gradle build time: Tuesday, November 20, 2012 11:37:38 AM UTC
    Groovy: 1.8.6
    Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
    Ivy: 2.2.0
    JVM: 1.6.0_45 (Apple Inc. 20.45-b01-451)
    OS: Mac OS X 10.8.3 x86_64

Add a build.gradle to your project

Add the following build.gradle file to the root of your Android project:

Build your project

You should now be able to build your project using the following command:

    $ gradle clean installDebug