Intro to Android

Maven

Maven is a dependency management system that also packages builds.

Installation

Please ensure that you have installed and configured maven. You can obtain maven here: http://maven.apache.org/download.cgi

Once installed, run mvn -v to verify your install and $PATH configuration. The output should look something like this:

[colabug:/Users/colabug/Documents/Career/Books] mvn -v
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)
Maven home: /usr/local/bin/apache-maven-3.1.1
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"

Configuration

Here is some of my environment set-up (zsh):

export ANDROID_HOME=/usr/bin/android-sdk-macosx
export M2_HOME=/usr/local/bin/apache-maven-3.1.1

export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$M2_HOME/bin:$PATH"

Dependency Management

You specify which libraries you'd like to use in the pom.xml file, which lives at the root level in your project.

<dependencies>
    <!--Unit testing-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Anything from maven central (http://maven.org) is fair game. These libraries are downloaded for you and stored away in your ~/.m2/repository directory.

Note: It's possible to point to other repositories and/or host your own. That's outside of the scope of this class.

Building

When you run mvn clean install, you are running the entire build lifecycle, including tests. It uses the build plugins that you specify to build a particular type of application.

It's handy for adding scripts, continuous integration, and other hooks into your build process.

Further Reading: