Android Development using Maven

I’ve actually just started learning about thisĀ Maven-Android plugin. There are several reasons why I think using Maven will speed up the development cycle:

Installing Maven

You can download maven (as of this writing, the latest version is 3.0.3) here:

http://maven.apache.org/download.html

Instructions on how to install Maven for Windows, Linux or Mac is on the same link above.

Creating your Android project

Before we create our application, make sure that you have the Android SDK installed properly. The easiest way to create a project using Maven is to use the archetype from:

https://github.com/akquinet/android-archetypes/wiki/Android-release-archetype

This archetype is already in the Maven Central repository so you don’t need to install or configure anything aside from running the mvn command. We will be using the following command to generate our project.

Most of them are self-explanatory but if you are not familiar with them, try to read Maven’s guide to naming conventions for groupId, artifactId and version here:

http://maven.apache.org/guides/mini/guide-naming-conventions.html

You will notice that maven will ask you what platform version you want to use in your application. In our case, we will just leave it as the default which is platform 7 or android 2.1. If you want to know more about the Android Platform Levels, take a look at this post:

http://developer.android.com/guide/appendix/api-levels.html

After running the command, it will create a directory my-android-project which contains the following files:

my-android-project - will contain your project sources, proguard configuration, AndroidManifest.xml and other resources.

my-android-project-it - this is the integration test project which can be used to run instrumentation tests on the emulator or a device.

You should replace test-key.keystore with your own keystore, either self-signed or purchased from providers. For more information about creating your own self-signed keystore, check this post:

http://developer.android.com/guide/publishing/app-signing.html

Let Maven do the Magic

Now you can compile, install and test your app by just using a very simple command:

This will automagically install the two APKs (my-android-project and my-android-project-it) into your device or emulator (if it is running). You will notice the following logs which shows the command that installs and executes integration tests:

Since the integration test application is empty right now, you will not see anything being executed at all on your device.