Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android support library setup with maven

I'm kind of new to Android.

I'm setting up a maven module for android application (it's inside an existing multi-module project), which uses Google Support Libraries (v4, v7, v13). What is the most adequate way of making it work with maven.

I want my project to be able to build with Jenkins (Maven), so I can't link any IDE specific projects or any means of non-maven dependencies.

Any options to combine maven/gradle in Jenkins are also acceptable.

like image 719
inteloid Avatar asked Aug 22 '13 12:08

inteloid


People also ask

How do I add a library Android support v7 Appcompat in Android Studio?

In the Properties window, select the "Android" properties group at left and locate the Library properties at right. Select /path/to/appcompat/ and Click Remove. Click Add to open the Project Selection dialog. From the list of available library projects, select v7 appcompat library and click OK.

How do I install support library?

Downloading the Support LibrariesStart the android SDK Manager. In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder. Select the Android Support Library item. Click the Install packages button.

Which v7 support libraries are used for modifying UI settings?

v7 Preference Support Library The preference package provides APIs to support adding preference objects, such as CheckBoxPreference and ListPreference , for users to modify UI settings. The v7 Preference library adds support for interfaces, such as Preference. OnPreferenceChangeListener and Preference.


2 Answers

Besides the maven-android-sdk-deployer, if you always have Android SDK installed with Google extras like me, you can define a local repository in your projects POM file and let maven download the dependencies from this local one.

The rational behind this is that, Google has already release the extra addons in a maven repository compatible directory layout. For my own machine, it is like this:

jerry-mac-mini:android jerry$ pwd /Users/jerry/adt-bundle-mac-x86_64-20130917/sdk/extras/android jerry-mac-mini:android jerry$ tree m2repository m2repository ├── NOTICE.txt ├── com │   └── android │       └── support │           ├── appcompat-v7 │           │   ├── 18.0.0 │           │   │   ├── appcompat-v7-18.0.0.aar │           │   │   ├── appcompat-v7-18.0.0.aar.md5 │           │   │   ├── appcompat-v7-18.0.0.aar.sha1 │           │   │   ├── appcompat-v7-18.0.0.pom │           │   │   ├── appcompat-v7-18.0.0.pom.md5 │           │   │   └── appcompat-v7-18.0.0.pom.sha1 │           │   ├── 19.0.0 │           │   │   ├── appcompat-v7-19.0.0.aar │           │   │   ├── appcompat-v7-19.0.0.aar.md5 ............. 

So, I just need to put some extra lines in my POM file like this, and the "env.ANDROID_HOME" is the environment variable pointed to Android SDK installation path.

<repositories>     <repository>         <id>android-support</id>         <url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>     </repository> </repositories>     ...... <dependency>     <groupId>com.android.support</groupId>     <artifactId>support-v4</artifactId>     <version>19.0.1</version> </dependency> 

After these steps, Maven in my ADT enabled Eclipse and console are both happily to resolve the desired dependencies, like this:

jerry-mac-mini:android-app-project jerry$ mvn dependency:tree [INFO] Scanning for projects... [INFO]                                                                          [INFO] ------------------------------------------------------------------------ [INFO] Building android-app-project 0.0.5-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: file:///Users/jerry/adt-bundle-mac-x86_64-20130917/sdk/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.pom Downloaded: file:///Users/jerry/adt-bundle-mac-x86_64-20130917/sdk/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.pom (403 B at 28.1 KB/sec) Downloading: file:///Users/jerry/adt-bundle-mac-x86_64-20130917/sdk/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar Downloaded: file:///Users/jerry/adt-bundle-mac-x86_64-20130917/sdk/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar (621 KB at 16783.8 KB/sec) [INFO]  [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ android-app-project --- [INFO] team.apollo:android-app-project:apk:0.0.5-SNAPSHOT [INFO] +- com.google.android:android:jar:2.3.3:provided [INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.0.1:provided [INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.0.1:provided [INFO] |  |  \- commons-codec:commons-codec:jar:1.3:provided [INFO] |  +- org.khronos:opengl-api:jar:gl1.1-android-2.1_r1:provided [INFO] |  +- xerces:xmlParserAPIs:jar:2.6.2:provided [INFO] |  \- org.json:json:jar:20080701:provided [INFO] +- com.android.support:support-v4:jar:19.0.1:compile [INFO] +- com.google.code.gson:gson:jar:2.2.2:compile [INFO] +- de.mindpipe.android:android-logging-log4j:jar:1.0.3:compile [INFO] \- log4j:log4j:jar:1.2.16:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.339s [INFO] Finished at: Mon Mar 24 14:32:00 CST 2014 [INFO] Final Memory: 10M/325M [INFO] ------------------------------------------------------------------------ 
like image 181
Jerry Tian Avatar answered Oct 11 '22 21:10

Jerry Tian


unfortunately those libraries are not in the central maven repository. so you have to use the maven-android-sdk-deployer (link) to install the libraries into your maven repository. then add the needed libraries to your pom.xml file as described in the readme.

like image 45
sebastian Avatar answered Oct 11 '22 21:10

sebastian