Use Maven with Android project

In order to mavenize (existing or not) Android project in Eclipse few steps are required:

1. Install m2eclipse plugin

All instructions how to do it, You will find here.

2. Install ‘Android Configurator for M2E

in Eclipse go to menu:

Help -> Eclipse Marketplace

search for ‘Android Configurator for M2E’ and install it:

Here is plugin’s website. Any additional info will be provided there. Moreover here is very detailed description about Android development with Maven.

3. Install Maven 3.0.3

Android Configurator for m2e requires Maven in version 3.0.3 or higher, and m2eclipse comes with lower version. There is need to update it. Use download source site for Maven 3.0.4 and unzip it. Then in eclipse go to:

Window -> Preferences -> Maven -> Installations

and set path to downloaded files (click ‘Add‘):

4. Create pom.xml

Here is sample pom.xml from plugin’s website. The most important differences between this, and standard pom.xml are marked with green.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.simpligility.android</groupId>
    <artifactId>helloflashlight</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>HelloFlashlight</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>1.6_r2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <sourceDirectory>src</sourceDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.2.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <!-- platform or api level (api level 4 = platform 1.6)-->
                        <platform>4</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

If you need some more info on basic configuration of pom.xml for m2eclipse, look  here.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

2 thoughts on “Use Maven with Android project

Give Your feedback: