Android Continuous Integration with ANT and Jenkins: Part 1
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.