Getting started with Gradle on the command-line is easy!
Download Gradle (see specific links below) and then extract the Gradle distribution to a folder, which we will call GRADLE_HOME. Add GRADLE_HOME/bin to your PATH environment variable.
Download Gradle 1.8 from the Gradle web site. At the moment, Android Studio v0.3.0 requires 1.8 now.
Download Gradle 1.6 from the Gradle web site. At the moment, only Gradle 1.6 works correctly with Eclipse. Using Gradle 1.7+ will fail with a cryptic error.
Define the ANDROID_HOME environment variable which points to your Android SDK.
// Unix
export ANDROID_HOME=~/android-sdks
// Windows
set ANDROID_HOME=C:\android-sdks
Afterwards, you have to configure the GRADLE_HOME environment variable on your path:
export GRADLE_HOME=/your_gradle_directory
export PATH=$PATH:$GRADLE_HOME/bin
In order for Gradle to work, ensure you have the API 17 SDK installed including the latest Android SDK Platform-tools and Android SDK Build-tools. Check this in the Android SDK Manager from within Eclipse.
Finally, you can check your working installation by running:
gradle -v
To use Gradle in your Android application, you have to create a build.gradle
file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion '17'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
instrumentTest {
java.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
assets.srcDirs = ['tests/assets']
resources.srcDirs = ['tests/src']
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
Note that with Gradle 1.6 as downloaded above, the SDK version must be specified as 17. Changing to 18 at this time may break the Gradle build.
The following commands can be used now. To do a full build:
gradle build
If a build occurs and you see the output:
BUILD SUCCESSFUL
Total time: 5.738 secs
Then Gradle is successfully setup for your project. If you get an error, try googling the error. Usually the issue is that you need to install the build tools or make sure to use Gradle 1.6.
Check out the following links for more details: