Maven: The Complete Reference
Before you attempt to build your Android libraries and applications with Maven, you will need to install the Android SDK and potentially install the Android API jar files into your local Maven repository or your repository server.
The Android Maven Plugin requires the presence of the Android SDK in your development environment. Install the SDK following the directions on the Android Developer web site.
ANDROID_HOME environment variable should be configured to point
to the installation directory of the Android SDK. For example if the
SDK is installed in /opt/android-sdk-linux this can be achieved with
on a Unix/bash based system or
on a Windows system.
In addition to the SDK, the various platform versions you need for development should also be installed following the instructions. You can install a subset of available platforms or simply install all available versions.
Optionally, the path
ANDROID_HOME/platform-tools can be added to the PATH variable to
allow easy command line execution of the various tools provided with
When building an Android application with Maven the compile process needs access to the Android API for the specific platform version the project is configured against. The Android SDK ships this as android.jar files in the different platform folders. In order for Maven to access these libraries, they need to be available in the local Maven repository.
Typically artifacts are available in Maven Central, however only the platform versions available in the Android Open Source Project are published to Maven Central. Newer versions of the platform as well as the compatibility package and proprietary extensions like the Google Maps support are not available there and need to be published to your Maven repository, if you want to use them in your Android project.
The artifacts published to Maven central are available as dependencies
under the groupId
com.google.android with the artifactId
The Maven Android SDK Deployer has been created to publish artifacts from the Android SDK into your local repository or repository server when using components that are not available in Central.
Download the tool by clicking on the
Download Source button and
extract the downloaded zip or tar archive in a folder of your
choice. A folder with a naming pattern of
mosabua-maven-android-sdk-deployer-XXX with XXX being a revision
number like df824df will be created.
In order to install the android jar files from the different platform revisions into your local repository you run the command in the deployer folder.
cd mosabua-maven-android-sdk-deployer-df824df mvn clean install
By default this will install all android.jar, maps.jar, usb.jar files
and the compatibilty packages into your local Maven repository. You
should find all newly installed files in the
group identifiers under ~/.m2/repository.
The above deployment works fine for one machine, but if you need to supply a whole team of developers and a cluster of build machines with the artifacts, you will want to deploy the artifacts once to a remote repository server that is available to all users. If you are not currently using a repository manager, you should download Nexus and configure a user with permission to deploy artifacts to a repository. To get started with Nexus, read the Nexus Installation chapter in the free, online Nexus book.
As a first step you will need to edit the
repo.url property in the
pom.xml in the top folder of the Maven Android SDK Deployer tool to
point to the repository you want to publish to. Alternatively you can
provide this property in the settings file or with
on the command line.
Then you need to add a server with the correct access credentials for the server to your Maven Settings file.
Snippet for settings.xml for the repository server access credentials.
<settings> <servers> <server> <id>android.repo</id> <username>your username</username> <password>your password</password> </server> </servers> </settings>
Once that configuration is completed, you can deploy the artifacts with
mvn deploy. As a result you should find the artifact in
the repository of your remote server.
By default the Maven Android SDK Deployer tool will attempt to install or deploy all versions of the platforms artifacts into a repository. If you decide to only install a subset of the components the tool can be used with profile options to only install or deploy some artifacts. This can be done by specifying the platform API versions as a profile name.
mvn install -P 3.2
Further details are available in the Maven Android SDK Deployer documentation.