Share
Introduction
"Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible."
"Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible."Martin Fowler
The structure of our project P1 will be:
The P1 project including AP1 application's main project and its tests in AP1Test.
To create these projects you should follow this sequence:
P1's pom.xml
We are using maven-android-plugin here, visit its site for further details.
Basically we
AP1Test's pom.xml
Just run
or download from its page and run it locally.
There's an alternative for this step, maven-android-sdk-deployer, however I prefer the simplicity and flexibility of the android-mvn-install script.
This example show how java activation framework was added to dependencies.
If activation is not on the repositories you have to add it using
To be able to use the double environment setup you should also add the external library to Eclipse. In project's Properties add the external jar file as displayed here.
Comments are gladly welcome.
Source
We have written some tests for our project and now we would like to take continuous integration into account, mainly if we are working in an enterprise development environment and our team has several developers.
We all are very much accustom to use Eclipse and Android ADT as our main developer environment, so it's logical that even though we are increasing our team size we don't want to left behind that experience and start using a different tool from scratch. At the same time, it's pretty clear that using maven as a build tool for the project we obtain a great level of simplification, mainly if we use hudson, cruise control or similar continuous integration tools.
That's why the approach presented here is to let both models co-exist.Project Structure
We are also considering here that a VCS is used and a parent project containing both the main and test project is under this VCS control.The structure of our project P1 will be:

The P1 project including AP1 application's main project and its tests in AP1Test.
To create these projects you should follow this sequence:
- Create a Project (File -> New... -> Project), P1 in this case
- Add a pom.xml file (File -> New... -> Other -> Maven -> Maven POM file). We will review its content later
- Create an Android Project (New... -> Android Project), AP1, using P1 folder instead of the default location, but DON'T create the test project yet or it will fail (ADT 0.9.5)
- Add a pom.xml file to AP1 (File -> New... -> Other -> Maven -> Maven POM file). We will review its content later
- Selecting AP1 project, create the corresponding test project AP1Test (Android Tools -> New Test Project) using again P1 as the location
- Add a pom.xml file to AP1 (File -> New... -> Other -> Maven -> Maven POM file). We will review its content later
- You can now import the whole project structure to your VCS
Pom Files
You need to define some things inside your pom files in order to get the Android projects correctly built.P1's pom.xml
We are using maven-android-plugin here, visit its site for further details.
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
Basically we
- define our source directory as src to be compatible with the Eclipse Android project structure
- configure the maven-compiler-plugin according to our needs
- clean Eclipse Android project structure too in our clean goal
- configure maven-android-plugin defining the location of the Android SDK. This can be defined here or read from the environment
- define our modules, in this case the main project AP1 and its tests AP1Test
- define the dependencies, android 2.1 in this case
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
AP1Test's pom.xml
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" |
Populating your Local Repository
For maven to find android dependencies you must populate your local repository. To ease the task you can use android-mvn-install script which do all the hard work for you.Just run
1 |
$ wget -qO - http://android.codtech.com/android-tools/android-mvn-install | bash -s -- \ |
or download from its page and run it locally.
There's an alternative for this step, maven-android-sdk-deployer, however I prefer the simplicity and flexibility of the android-mvn-install script.
Building the project
Now we have several alternatives to build our project:- using Eclipse as usual for other Android projects using ADT plugin (i.e.: AP1 -> Run As -> Android Application)
- using Maven from Eclipse (i.e.: P1 -> Run As -> Maven build)
- using Maven from the command line (i.e.: mvn install)
- using a continuous integration tool
External Libraries
If your project uses external libraries they should be added to the Eclipse project and to Maven dependencies as well. The latter case may also imply that you have to install those libraries in the local or remote Maven repository.This example show how java activation framework was added to dependencies.

If activation is not on the repositories you have to add it using
1 |
$ mvn install:install-file -DgroupId=activation -DartifactId=activation -Dversion=1.1.1 -Dpackaging=jar \ |
To be able to use the double environment setup you should also add the external library to Eclipse. In project's Properties add the external jar file as displayed here.

Using Hudson
Having followed all the steps mentioned before we will now be able to create a job in hudson to build our project using maven.
Conclusion
There are still some rough edges and some things we haven't mentioned yet like running headless android emulators to be able to run the tests on the server. We will be covering these issues in future posts but I think that we have enough already to start applying continuous integration for our android projects.Comments are gladly welcome.
Source





