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).
- 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
You need Eclipse Indigo or Juno installed
Install Android Connector for Maven via the Eclipse Marketplace. Select Help -> Eclipse Marketplace… and search for android m2e.
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.
Create ANDROID_HOME environmental variable and assign location of the Android SDK into it.
- Click Start button
- Right click on the Computer and choose Properties
- Choose Advanced system settings
- Click Environment Variables…
- Click New below System variables window.
- Variable name should be: ANDROID_HOME.
- Variable value should be location of the directory containing Android SDK.
Click OK and save your data.
Go to the following website: http://maven.apache.org/
Go to the download section (http://maven.apache.org/download.html) and download Maven (version 3.0.4 is preferred – Binary zip)
Extract zip archive and copy apache-maven-3.0.4 directory into C: drive.
Location of the extracted directory should be as follows: _C:\apache-maven-3.0.4_
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.
Add platform-tools directory from Android SDK directory to the Path environmental variable respectively.
Click Start button and then choose Run option (click Windows button + R key on your keyboard) and type: cmd.
Type: mvn –v
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”
Now Maven should be properly configured and prepared for deployment of the Android applications.
Importing, building and running sample Maven Android project
- Download samples from the stable branch on the website: http://code.google.com/p/maven-android-plugin/wiki/Samples
- Extract downloaded archive.
- Open Eclipse IDE.
- Import helloflashlight project (as an Android project).
- Right click on the project.
- Choose an option Configure -> Convert to Maven Project.
- Dependencies and project configuration are defined in pom.xml file.
- Click Start button and then choose Run option (click Windows button + R key on your keyboard) and type: cmd.
- Go to the directory, where the current project (helloflashlight) is located.
- Type in the command line: mvn clean install
- Command from previous point will create .apk file in the target folder.
- Type in the command line: mvn android:deploy
- 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.
- You can start the application via Maven by typing the following command: mvn android:run
Summary - Pros & Cons
- 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.
- 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.