Automating Android builds with Maven

I have been working on an Android application the past month or so. My colleagues are all using Eclipse and have been working with the tooling provided for this platform. This is a good way to get up to speed fast and produce the first prototypes of an application. Going forward though automation is required. Both for builds and for test execution.

On all other java projects we use Maven as out tool for automation so it would be a shame to throw away the good momentum by replacing this with ant in the Android project. Instead I made the decision to try the android maven plugin created by Hugo Josefson at Jayway. It's a neat little plugin to Maven and it's easy to set up without changing the project structure required by the Eclipse users.

The first step is to set up you environment. I'm using bash as my shell so I added the following line to my .bash_profile file:

It is important that this point to the root of the SDK and not to one of the platforms within. Also, I choose to use ANDROID_HOME instead of ANDROID_SDK_15 used at the maven-android-plugin documentation.

To enable your Android project to be built with Maven you need to add a pom looking like this to the project root:

In order for Maven to find the android.jar file specified as a dependency in the pom you need to install it into you local repository. You the below command:

This will set up you project to compile against Android 1.6. If your project is built against 1.5 or 2.0 you just replace the references to 1.6 with your preferred version.

Next post will show how to add maven to your Android unit test project.

  • Quentin

    Hi,Thank you for this useful post. I hope next post will be publisher very soon !!Regards,

  • Quentin

    Hi,

    Thank you for this useful post. I hope next post will be publisher very soon !!

    Regards,

  • Tomas Malmsten

    Good that you found it useful.

    I have posted the next article in the series now and will put together the last one as soon as I've got time.

    Tomas

  • Tomas Malmsten

    Good that you found it useful.I have posted the next article in the series now and will put together the last one as soon as I've got time.Tomas

  • mosabua

    Thanks for the posts Tomas. Would you mind putting some help into the plugin documentation itself?

  • mosabua

    Thanks for the posts Tomas. Would you mind putting some help into the plugin documentation itself?

  • Tomas Malmsten

    I will be posting this and the two others onto the wiki. Hugo just gave me credentials to post content there.

  • Tomas Malmsten

    I will be posting this and the two others onto the wiki. Hugo just gave me credentials to post content there.