Category: Automation

Automating Android test project with Maven

The last post explored how to enable Maven builds in a standard Android Eclipse project. This post will show how to enable the test project to be built with Maven.

It will be a bit simpler to enable Maven builds in the test project since we will not need to do any of the prep work. The only thing required is to create a pom file for the test project:

This pom is similar to the pom in the main project but has two more dependencies. They are both pointing to the main project, one to the apk and one to the jar file. The dependency to the jar file is to enable the compiler to find your java classes from the main project. The dependency to the apk is to enable the android maven plugin to find the apk that it will run the tests against on the device or emulator when executing.

The android maven plugin can now run the tests using instrumentation, just like Eclipse does, as long as an emulator or Android device is connected. It uses the same underlying tools.

In order to execute the test the main project needs to be built and installed into the local Maven repository. This is done with the mvn install command in the main projects root folder. When the main project have been installed the same command, mvn install, will build and execute the tests when executed from within the test projects root.

Next post will explain how to create a project hierarchy that makes it possible to build and test the two projects with one command.

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.

Automating android builds

I have been woking with an Android application for a week and a bit. It’s an interesting experience. The API’s are easy to use and it feels like a platform that is highly productive. Especially if you work in Eclipse.

On the flip side of this comes the badly documented ANT tasks. I have not been able to find any documentation at all on how to use them! This have resulted in having to use the shell commands that ships with the Android SDK. This is all but ideal however since this level of detail could have been hidden away, and seems to be hidden away, in the ant tasks that also ships with the SDK.

I have been greatly help in my endeavor to automate the build and deploy to the emulator by reading the blog postings done by Gabor Paller at his blog http://mylifewithandroid.blogspot.com/. His early posts that details how to create ANT scripts and work with Android in a shell environment were a true life saver.

The result is in any case an ant script that will build and deploy all source files onto a running AVD. There are also targets for redeployment and uninstall of the application. You can download it from here.

If anyone have documentation on how to use the ANT tasks for android or if you know of other ANT tasks that will do the same kind of job please post a comment.