Tutorial details

Building Android Apps with Apache Maven | App Code for Sale | Preview

Building Android Apps with Apache Maven | Android Tutorial

How to build Android applications with Apache Maven and the "android-maven-plugin"

Overview PAGE TOP

Lars Vogel

Version 0.3

Copyright © 2011, 2012 Lars Vogel



Android Maven

This tutorial describes how to build Android applications with Apache Maven and the "android-maven-plugin".

1.1. Android SDK and ADT PAGE TOP

The Android SDK provides tooling for the command line to create and build Android projects.

The Android Development Tools (ADT) offer the same functionality for Eclipse. In Eclipse you can manually export Android applications via the Eclipse wizard.

To build and deploy Android application the Android SDK provide tools which are currently based on Apache Ant.

The project lead of the ADT has recently announced that ADT is moving to a Gradle based build system and that the Eclipse tooling is also going to be based on the same build system.

Tooling for building Android Application with Maven are also available. The move of ADT to Gradle makes the support of Maven easier as Gradle uses Maven repositories to manage its dependencies.

1.2. Maintain PATH PAGE TOP

Building Android outside Eclipse involves using the command line or shell. You should be familiar with using a shell in case you want to be able to perform this tutorial.

Make sure that the tools and platform-tools folder of the Android SDK installation directory are part of your PATH environment variable.

2. Building Android Applications with Maven PAGE TOP

Apache Maven is a popular build tool. For Maven there is the android-maven-plugin plug-in available, which allows to build Android applications via Maven.

The homepage of this maven plug-in is located under: Android-Maven Plug-in .

You only have to install Maven, write a correct pom.xml file and issue the commands to Maven to build, install and run your application.

The following will build your Android application via Maven.

mvn3 clean install

This will create the application and places the .apk file in the target folder.

If you want to install the application via Maven on your Android device, you can use the following command.

mvn3 android:deploy

If more then one device is available you can specify the relevant device in your pom.xml. Maven can also start and stop an Android virtual device automatically for you.

You can also start the application via Maven.

mvn3 android:run

3. Tutorial: Building Android Applications with Maven PAGE TOP

Create a new Android project called "de.vogella.android.build.firstmaven". The actual content of the repository is not important as we are only using this project to create a working build for Maven.

Create the following "pom.xml" file in your directory. Make sure that artifactId is set to your project name.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
 <name>Maven Example</name>

      <!-- platform or api level (api level 4 = platform 1.6) -->

Switch to the command line and enter the following command:

mvn3 android:deploy 

4. Move information PAGE TOP

For more information see the complete Maven Android Guide from Sonatype: Android Application Development with Maven .

Another quick starting guide is available on the android-maven-plugin project side: Getting Started with Android and Maven

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.