Sunday, 26 August 2012

Mavenized Android Project in Eclipse


A. Pre-requisites


1. Download and install Eclipse

Get eclipse: http://www.eclipse.org/downloads/

Tested with:
Eclipse IDE for Java Developers 4.2 (Juno)

2. Install ADT

http://developer.android.com/sdk/installing/installing-adt.html

3. Install Android API for all need levels.

I recommend 2.3.3 and up.

Whatever you are installing make sure you have at least the following packages:
SDK Platform
Samples for SDK
Google APIs


Optionally:
Sources for Android SDK

4. Install Maven support:

Help -> Install New Software ...
m2e

5. Install Git support:

Help -> Install New Software ...
egit

6. Install Android Maven integration for Eclipse

Help -> Eclipse Market Place
Android Configurator for M2E

Optionally you could also install:
Help -> Eclipse Market Place
Advanced UI Development Tool

7. Create a new Android Emulator setup:

Window -> Android AVD Manager

I usually have one for the "bottom" API level and another for "top", both with 16MiB extra flash disk.

B. Creating a "mavenized" Android project in Eclipse

http://rgladwell.github.com/m2e-android/
http://code.google.com/p/maven-android-plugin/

1. Create the maven project

File -> New -> Project...
Maven -> Maven Project

1.1. Select the archetype:

You probably want to go with android-quickstart from de.akquinte.android.archetypes

The maven plugin that is required is the maven-android-plugin
http://code.google.com/p/maven-android-plugin/

1.2. Complain about missing "src/test/java" directory

Create the directory (which is not create by the archetype)


2. Update pom.xml


2.1. Check if the android version is correct in the pom.xml:

     <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>2.3.3</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

2.2. Check the maven-android-plugin version:

            <plugin><groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.3.0</version>
                <!--
                    rest of the section
                -->
            </plugin>

3. Test your build:

Eclipse:
Run As -> Maven Install

Command line:
mvn clean install

4. Test your app:


4.1. Start the emulator:

Window -> AVD Manager
Start...

Note: Wait for complete startup

4.2. Install and run the application

Eclipse:
Run As -> Android Application

NOTE:

You can get the changes from GitHub: https://github.com/fgka/android.git

No comments:

Post a Comment