Android support library setup with maven

前端 未结 6 844
甜味超标
甜味超标 2020-11-27 15:55

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 Librar

6条回答
  •  星月不相逢
    2020-11-27 16:34

    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.

    
        
            android-support
            file://${env.ANDROID_HOME}/extras/android/m2repository
        
    
        ......
    
        com.android.support
        support-v4
        19.0.1
    
    

    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] ------------------------------------------------------------------------
    

提交回复
热议问题