Learning Android: Getting android-support jar/compatability package as a Maven dependency
Join the DZone community and get the full member experience.
Join For FreeIn the app I’m working on I make use of the ViewPager class which is only available in the compatibility package from revisions 3 upwards.
Initially I followed the instructions on the developer guide to get hold of the jar but now that I’m trying to adapt my code to fit the RobolectricSample, as I mentioned in my previous post, I needed to hook it up as a Maven dependency.
I added the dependency to my pom.xml like this:
<dependency> <groupId>android.support</groupId> <artifactId>compatibility-v4</artifactId> <version>r6</version> </dependency>But when I tried to resolve the dependencies (via ‘mvn test’) I ended up with this error:
Downloading: http://repo1.maven.org/maven2/android/support/compatibility-v4/r6/compatibility-v4-r6.pom [WARNING] The POM for android.support:compatibility-v4:jar:r6 is missing, no dependency information available Downloading: http://repo1.maven.org/maven2/android/support/compatibility-v4/r6/compatibility-v4-r6.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.878s [INFO] Finished at: Sun Jan 08 20:42:17 GMT 2012 [INFO] Final Memory: 8M/554M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project tweetboard: Could not resolve dependencies for project com.markhneedham:tweetboard:apk:1.0.0-SNAPSHOT: Could not find artifact android.support:compatibility-v4:jar:r6 in central (http://repo1.maven.org/maven2) -> [Help 1]A bit of googling led me to a demo project showing how to hook up the compatibility package. It linked to the Maven Android SDK Deployer which is:
The Maven Android SDK Deployer is a helper maven project that can be used to install the libraries necessary to build Android applications with Maven and the Android Maven Plugin directly from your local Android SDK installation.
I had to first clone that git repository:
git clone git://github.com/mosabua/maven-android-sdk-deployer.git
And then find the compatability-v4 package and install it:
$ cd maven-android-sdk-deployer $ cd extras/compatibility-v4 $ mvn clean install
I initially made the mistake of not setting $ANDROID_HOME to the location of the Android SDK on my machine, which led to the following error:
[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.484s [INFO] Finished at: Sun Jan 08 20:51:07 GMT 2012 [INFO] Final Memory: 3M/81M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project android-extras: Properties file not found: /Users/mneedham/github/maven-android-sdk-deployer/extras/${env.ANDROID_HOME}/extras/android/support/source.properties -> [Help 1]Setting it solves the problem:
$ export ANDROID_HOME=/Users/mneedham/github/android/android-sdk-macosx
There are more detailed instructions on the home page of the github project.
From http://www.markhneedham.com/blog/2012/01/08/learning-android-getting-android-support-jarcompatability-package-as-a-maven-dependency/
Opinions expressed by DZone contributors are their own.
Comments