Android Continuous Integration with ANT and Jenkins: Part 1

Share This

Recently we’ve started a new Android project for one of our customers, and since we are using a proper development workflow, I’ve began with setting up Continuous Integration (CI)  as a part of the process.

I’m going to tell you a little more than just the technical details about how to set up CI server and build an application there, what I’ll tell you is how we, at Black River, manage development and testing processes using Jenkins.

In this article, I’ll cover following topics:

  • How to create an ANT build script for the Android app
  • How to run unit tests from the Android test project with ANT
  • How to setup Jenkins CI for your Android project
  • How to integrate Jenkins with Github
  • How to make a release build and send the application to QA team

Let’s start with creating ANT build script, based on your eclipse project.

I assume, since you are going to setup CI for Android, you already have Android SDK installed.

First of all – get the latest version of Apache ANT here – http://ant.apache.org/bindownload.cgi and unpack it somewhere on your computer.

See Apache ANT website for installation details, in essence, it says that you need to add a few environment variables:

  • ANT_HOME – pointing to directory where you’ve unpacked ANT
  • ANT_OPTS – additional ANT settings (for example, you can limit the amount of memory that ANT may consume)
  • add %ANT_HOME%bin to your PATH variable

Now, if you run “ant” tool in your console (cmd.exe in Windows, terminal in *nix, etc), you’ll see something like the followin:

Buildfile: build.xml does not exist!
Build failed

Okay, now we’re ready to setup our ANT build scripts.

Go to your project directory with console and run the following command:

android update project -p .

Note that “.” (dot) after -p (path to project) flag, means “current folder”.
It will update and rebuild your Android project files and create build.xml file, which will be used by ANT to build your project.

Then go to your test project folder with console and run update command for the test project:

android update test-project -m _PATH_TO_ANDROID_PROJECT -p _TEST_PROJECT_PATH_

At this point, we have two projects with prepared and build.xml files.

Let’s try to build them!

Go to your project folder and run:

ant clean debug

This command should start compilation.
Afterwards, cd to your test project folder, start Android emulator and run in console:

ant all clean emma debug install test

This command will build the test project, run code coverage report with EMMA tool, install APK into emulator and run unit tests with JUnit on device

You’ll see the code coverage and unit tests results in your console window.

Okay, now we know how to build Android project and run tests from console with ANT tool.

It is a good start for build automation and as a result –  continuous integration for development process.

In the next articles, I’ll show you how to set up ANT to publish code coverage and JUnit reports, run Android ANT build with Jenkins CI server, get code from Github (or any other Git server) and run a couple of other useful and clever tasks.


13 Responses to “Android Continuous Integration with ANT and Jenkins: Part 1”

  1. Yev says:

    Nice start :) Though I am really interested in the further parts of this series. Do you know when will those be published?

  2. Robert Mendez says:

    This looks promising, thanks. When will the future parts be published?

  3. […] my recent post I wrote about how to build and run unit tests on Android project from command line. These were […]

  4. Karim Varela says:

    When I try to run:
    ant all clean emma debug install test

    I get an error that says:
    “Target “all” does not exist in the project ”

    Any idea what’s wrong?

  5. Alexandre says:

    Hi,

    I have a question. Why build didn’t fail when tests fail?
    My unit test are failing but my build is success!

    Thanks,

    Alex

    • Andrey Zavarin says:

      Hm, that is weird, make sure that “test” task is not overridden with something else. Default “test” task from build.xml provided with Android SDK should fail the build, if unit tests are not successul.

  6. Magno says:

    Which kind of test-project did you create?

  7. Ash says:

    Thank you for providing the clearest instructions for using eclEmma, Android Junit Tests (Robotium, in my case), ANT and Eclipse. I did have to open an emulator first because it kept stalling and removed “all” from the instructions to the tester. All other instructions found on the interwebz were not as straightforward (an not as user friendly to Command Prompt noobs). Thanks!

  8. Anushree says:

    when i type
    android update project -p.

    it is saying android : command not found

  9. […] Jenkins ou Windows. Outra fonte interessante é esse post do Black River, falando desta vez sobre integração contínua com ANT e Jenkins. Para finalizar Android e partir para o iOS, deixamos aqui esse vídeo do Google I/O que fala sobre […]

Leave a Reply

Recent OpenX Source / Revive Adserver Expandable Banners

OpenX Source / Revive Adserver Expandable Banners The following example demonstrates a 600px by 150px banner served by OpenX Source / Revive Adserver and expanded to 600px by 300px on rollover. The flash creative can be either uploaded to creatives directory directly (FTP) or just as an another OpenX Source / Revive Adserver banner (preferred). When uploading the SWF creative, you do not need to replace any hardcoded URLs or indicate a destination URL – that would be done in the HTML banner setup. Essentially, we are just using it as a storage container for our creative, all impressions and … read more

 Twitter  LinkedIn  Google+  Skype RSS

Get in Touch

  • r Phone:
    (416) 877 2844 / (647) 258 4847
  • h Email:
    company@blackriver.to
  • m Address:
    1454 Dundas St. East, Suite 124
    Mississauga, Ontario
    L4X1L4, Canada

Any Questions?

Email

Message

First month of the year?