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:
<project> <modelVersion>4.0.0</modelVersion> <groupId>org.jvending.masa</groupId> <artifactId>maven-test</artifactId> <version>1.0.1</version> <packaging>android:apk</packaging> <name>maven-test</name> <dependencies> <dependency> <groupId>android</groupId> <artifactId>android</artifactId> <version>1.0</version> </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <groupId>org.jvending.masa.plugins</groupId> <artifactId>maven-dx-plugin</artifactId> <extensions>true</extensions> </plugin> </plugins> </build> </project>
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.