Overview

Etymology

Maven, a Yiddish word meaning accumulator of knowledge.

What is Maven?

Maven is a tool that can be used for building and managing any Java-based project with all its dependencies (libraries).

Maven’s objectives

  • Making build process easy
  • Providing uniform build system (Project Object Model)
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

Setting up Maven Android projects on MS Windows

Configuring environment

  1. You need Eclipse Indigo or Juno installed

  2. Run Eclipse

  3. Install Android Connector for Maven via the Eclipse Marketplace. Select Help -> Eclipse Marketplace… and search for android m2e.

  4. Click the Install button next to the Android Connector for Maven that appears and follow the path through the wizard dialog to install the plug-in and its dependencies (including the Android Development Toolkit and the Maven for Eclipse m2e plug-in). Accept the terms-and-conditions and click Finish.

  5. Create ANDROID_HOME environmental variable and assign location of the Android SDK into it.

    1. Click Start button
    2. Right click on the Computer and choose Properties
    3. Choose Advanced system settings
    4. Click Environment Variables…
    5. Click New below System variables window.
    6. Variable name should be: ANDROID_HOME.
    7. Variable value should be location of the directory containing Android SDK.
  6. Click OK and save your data.

  7. Go to the following website: http://maven.apache.org/

  8. Go to the download section (http://maven.apache.org/download.html) and download Maven (version 3.0.4 is preferred – Binary zip)

  9. Extract zip archive and copy apache-maven-3.0.4 directory into C: drive.

  10. Location of the extracted directory should be as follows: _C:\apache-maven-3.0.4_

  11. Add C:\apache-maven-3.0.4\bin directory to the environmental variable called Path 1. Click Start button 2. Right click on the Computer and choose Properties 3. Choose Advanced system settings 4. Click Environment Variables… 5. Find Path variable and and click Edit 6. After semicolon (;) add path to the directory containing batch script inside the maven directory which should be as follows: C:\apache-maven-3.0.4\bin 7. Click OK and save your data.

  12. Add platform-tools directory from Android SDK directory to the Path environmental variable respectively.

  13. Click Start button and then choose Run option (click Windows button + R key on your keyboard) and type: cmd.

  14. Type: mvn –v

  15. The returned output should be as follows: * Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100) Maven home: C:\apache-maven-3.0.4\bin\.. Java version: 1.6.0_33, vendor: Sun Microsystems Inc. Java home: C:\Program Files (x86)\Java\jdk1.6.0_33\jre Default locale: en_US, platform encoding: Cp1252 OS name: “windows 7”, version: “6.1”, arch: “x86”, family: “windows”

  16. Now Maven should be properly configured and prepared for deployment of the Android applications.

Importing, building and running sample Maven Android project

  1. Download samples from the stable branch on the website: http://code.google.com/p/maven-android-plugin/wiki/Samples
  2. Extract downloaded archive.
  3. Open Eclipse IDE.
  4. Import helloflashlight project (as an Android project).
  5. Right click on the project.
  6. Choose an option Configure -> Convert to Maven Project.
  7. Dependencies and project configuration are defined in pom.xml file.
  8. Click Start button and then choose Run option (click Windows button + R key on your keyboard) and type: cmd.
  9. Go to the directory, where the current project (helloflashlight) is located.
  10. Type in the command line: mvn clean install
  11. Command from previous point will create .apk file in the target folder.
  12. Type in the command line: mvn android:deploy
  13. Command from previous point will install the application via Maven on your Android device or Android emulator (virtual device). If more than one device is available, you can specify the relevant device in your pom.xml file. Maven can also start and stop an Android virtual device automatically for you.
  14. You can start the application via Maven by typing the following command: mvn android:run

Summary - Pros & Cons

Pros

  • Uniform build system.
  • No need to search for external libraries.
  • Good quality project information.
  • Transparent migration to new features.
  • Single project configuration for libraries in team work.

Cons

  • Libraries in the repository are not always up to date.
  • Project configuration takes more time.
  • Mistakes in pom.xml file are not detected by IDE, but can cause fail of the build.
  • Necessity of using CLI (Command Line Interface) in some cases.

Additional resources & references

  1. Maven reference book
  2. Maven reference book – Android Development Section
  3. Maven Android Plugin
  4. Vogella’s article about Maven & Android
  5. Eclipse plugin for Maven Android projects
  6. Maven repository