Tallan Blog

Tallan’s Experts Share Their Knowledge on Technology, Trends and Solutions to Business Challenges

Build your Android project in one step with Maven


I will assume the following has been installed and configured.

  • Android SDK (r07 or later)
  • Maven 3 (version 3.0.3)
    1. Set environment variable ANDROID_HOME to point to the root directory of the Android SDK.
    2. Add ANDROID_HOME/tools to your PATH environment variable.
  • An Android project to build


Building an Android project consists of 3 steps. The code is compiled to create an executable apk file, then the apk is signed and finally zipaligned to optimize disk space usage on the mobile device.

Executing these steps manually is prone to human error and can lead to bad builds. This can happen due to forgetting to sign the package, missing dependencies, etc. It is also time consuming especially if you have fast iteration cycles and/or multiple build configurations for different version of the Android OS. Using Maven and android-maven-plugin we can create a one step process to manage dependencies, build, sign and zipalign your Android project.

In this post I will walk you through the setup we have for TASS Mobile, our internal Android client for our time tracking application.

Breakdown of pom.xml

Basic information

The pom.xml file is the configuration file that tells Maven how to build the Android project. The first section of the configuration file includes basic information about the project such as name, groupId and version number. This is what it looks like for our TASS mobile app.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <name>TASS Android</name>


This is where Maven really facilitates the build process. The TASS Mobile app for Android uses the guice and roboguice libraries for dependency injection. Fortunately guice and roboguice are available in the Maven central repository so all we need to do is include them under the dependency section along with the Android library. Make sure the Android version matches your target Android version.


Build Steps

The standard maven-compiler-plugin in conjunction with maven-android-plugin will create the application apk file, it will also zipalign it after signing the apk which we cover in the next step. Make sure the platform variable is set to the target device Android OS version.


In this section we configure maven-jarsigner-plugin to sign the apk file. Set the keystore, storepass, keypass and alias parameters with you own.


This step consolidates the application version in the pom.xml file with application version in the AndroidManifest.xml file. This will come handy when you setup a fully automated release management process.

                try {
                def manifestFile = new File("AndroidManifest.xml")
                def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "ns")
                def parser = new groovy.util.XmlParser(false, true)
                def rootNode = parser.parse(manifestFile)
                def attributes = rootNode.attributes()
                attributes[ns.versionName] = "${project.version}"
                def writer = new groovy.io.GroovyPrintWriter(manifestFile)
                writer.println('&lt;?xml version="1.0" encoding="UTF-8"?&gt;')
                def xmlWriter = new groovy.util.XmlNodePrinter(writer)
                } catch (FileNotFoundException e)
                println('No AndroidManifest.xml file found. Skipping version update.')
                println('Probably not an Android project, but a library.')
                println('Skipping version update.')


This is the default profile I’ve created for building, signing and ziapligning the project. There are other options available but this is all you need to create a usable build.


Once you have configured your project all you need to do is type the following command and Maven will build a binary ready to run on your Android device. Look for the apk file under the target/ folder in your project.

mvn clean install -Prelease

or simply

mvn clean install



Learn more about Tallan or see us in person at one of our many Events!

Share this post:

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>