Resources Blog MASA: Building Android Applications With Maven

MASA: Building Android Applications With Maven

When I first downloaded the SDK for Android nearly a year ago, I was greeted by an ant build file. I wanted to start developing Android applications but wasn't willing to go back to ant to do it; so I decided to throw together a quick set of plugins to build Android with Maven: MASA Plugins. The name MASA comes from PKD's book We Can Build You. In the book, there is a company MASA Associates (Multiplex Acoustical System of America), responsible for building simulacra (or androids). PKD's MASA is also a play on the word NASA, and as we all know, Maven is as simple as rocket science.

After starting, I found there was little documentation on how to use the command line to build Android apps, leading me to dissect the build.xml file to learn how the command line options worked.

After that, it was just a matter of creating a custom lifecycle for the packaging type 'android:apk'. The plugins largely consisted of translating POM parameters to the command line, similar to Apache NMaven, undergoing incubation at the ASF.

A sample POM looks like:


So by specifying the packaging type as 'android:apk' and the sourceDirectory as 'src', you can build your android project with Maven. If you type 'mvn install -Dmasa.debug' the plugins will also deploy the apk to the G1 device over USB or to the emulator.

For the latest SDK, I included the packaging type: 'android:apk:platformTest'
that will deploy the apk to the device and run the unit tests on the target device.

At the time, the Android source was not open-source, so MASA provides a build script for importing the android.jar into the local repo. Now that Android is open-source, I'll be looking to deploy the android.jar into the Maven repo to avoid this additional step and then getting a release of MASA deployed as well.

One area that I still need to work on is the delayed signing of apks, so expect to see future updates.

Picture of Shane Isbell

Written by Shane Isbell

Shane is a former Developer at Sonatype. He has 15 years of experience developing in mobile and embedded environments and is an expert in Android and Java. He works across the full-stack from embedded to server and is passionate about open-source.