DEV@cloud » Android Gradle Builds

Android Gradle Builds

Last modified by Steve18 Harris on 2014/03/28 22:41

gradle-logo.png

Overview

To help you configure CI builds using the new Android Gradle Build System on DEV@cloud, there is a complete example online that runs a Gradle build and instrumentTest using an AVD configured with the Google and Android APIs target ("Google Inc.:Google APIs:17").  

You can also find more information on the CloudBees Android documentation page.

Getting Started

The source  for the project is organized following Google's recommended Project Structure, with two separate source sets: /src/main for the main source code and /src/instrumentTest for Android unit test code.  It is possible to vary this structure as described in the document from Google.

To run a build, make sure that you have at least Gradle 1.6 installed: you can check this by going to Jenkins -> Configure Jenkins -> Grails and clicking on "Grails Installations".  In general, you should choose "gradle-latest" and check "Use pre-installed Gradle on DEV@cloud" box.  

To configure the Gradle build, add a build set "Invoke Gradle Build" using the "gradle-latest" version and configure the Tasks that you want to run.  For a simple build, you might use "gradle clean build"; to run unit tests on an AVD emulator on DEV@cloud, start the Android emulator in the usual way and specify "clean connectedInstrumentTest" for the target.  

Remember that if your applications uses Google API services, then you will need to specify an appropriate target, as in the partnerdemo example.

There is an example Gradle build file at the bottom of this document that you can use as a template for your builds.  

Note that a number of Google Android libraries (such as play-services and gcm-client in this example) are NOT available from Maven Central: you will either need to copy these from the appropriate location under the Android SDK installation (/opt/android/android-sdk-linux/ on DEV@cloud) to your project's libs directory, or you can use the Maven Android SDK Deployer project (from GitHub) to deploy the libraries to your CloudBees private maven repository.

The advantage of the latter approach is that library dependencies can be specified using standard maven co-ordinates. There is an example build showing how to build and deploy to the private CloudBees maven repository online. To reference the CloudBees repository from your local Gradle builds, you will need to configure your ~/.m2/settings.xml and ~/.m2/settings-security.xml as described in this article.

If you are running Android unit tests with "connectedInstrumentTest" or "connectedCheck", you will find the results in the workspace under **/build/instrumentTest-results/connected/*.xml.

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

task wrapper(type: Wrapper) {
    gradleVersion = '1.6'
}

apply plugin: 'android'

repositories {
    mavenCentral()
    maven {
        url "https://repository-partnerdemo.forge.cloudbees.com/release/"
    }
}

dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:support-v4:13.0.0'
    compile 'com.google.android.gms:play-services:3.1.36'
    compile 'com.google.android.gcm:gcm-client:3'
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"
}
Tags:
Created by Mark Prichard on 2013/07/22 20:14