Jan29

Build Android Applications Using Apache Maven

Apache Maven is an innovative software tool used to build and manage projects. Based on Project Object Model (POM), Maven can manage everything from a project’s build, reporting and documentation – all from a central piece of information.

Using the Maven tool to build Android applications is still a new concept that’s not widely adopted by the Android App Development community.  Instead, the preferred development tool for Androids is Eclipse IDE, which also provides the opportunity to build related functionality. Despite its unpopularity, there are still a hand full of developers who use Maven to manage projects and resolve all build related complications.

When building an Android application, generating application packages (.apk) can present complications in terms of Maven project setup, configuration and ensuring its operational.   Some of the challenges include launching Emulator, creating an .apk file and installing the application on an Android device.

Below are steps and recommendations to configure Maven to build an Android application.

1.  Download and install JDK 1.6 or 1.7

2.  Download and install Maven 3.1.1+

Example:  C:\apache-maven-3.1.1

3.  Install ANDROID SDK

Note: It is important to remember the Android SDK download location. In this tutorial, we are considering it as C:\Android\android-sdk

4.  Setup JDK, Android SDK and Maven environment variable:

Image 1

 

Image 2

SET PATH (environment path variable):

C:\jdk1.7.0_45\bin;
C:\ apache-maven-3.1.1\bin;
%ANDROID_HOME%\tools;
%ANDROID_HOME%\platform-tools;

Note: Try system environment variable if user variable is not reflecting.

Build and Verification

To verify Maven build setup, we will proceed with sample Android project. Download a sample Maven Android Project.

After successfully downloading and extracting archive file, navigate to the directory below:

\jayway-maven-android-plugin-samples-4d8d535\helloflashlight

Verification

Open command prompt and navigate to helloflashlight directory and test maven command

Image 3

Generating final build Application package (.apk)

Image 4

Once BUILD SUCCESS, verify the final application build file in the target folder

C:\jayway-maven-android-plugin-samples-4d8d535\helloflashlight\target

To setup a successful Android Maven project, understanding of POM.xml file is very important. Once the build is successful, make sure you visit pom.xml file and verify the Android dependency. Here are some key Android related dependency mentioned in pom.xml

image 5

Image 6

Let us know what you think – are there other tools that you use to build Android Apps with?  If so, let us know your best practices in the comments section below.

Leave a Comment

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