Android support library setup with maven

前端 未结 6 825
甜味超标
甜味超标 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:14

    I've simply used the system scope feature provided by maven

    <dependency>
       <groupId>com.google.android</groupId>
       <artifactId>support-v4</artifactId>
       <version>19.0.1</version>
       <scope>system</scope>
       <systemPath>${env.ANDROID_HOME}/extras/android/support/v4/android-support-v4.jar</systemPath>
    </dependency>
    
    0 讨论(0)
  • 2020-11-27 16:27

    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.

    0 讨论(0)
  • 2020-11-27 16:28

    Thanks to Google. You can now do this

    • Make sure that the repositories section includes a maven

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
    
    • Add the support library to the dependencies section

    dependencies {
        ...
        compile "com.android.support:support-core-utils:25.3.1"
    }
    
    0 讨论(0)
  • 2020-11-27 16:30

    I've just run into the same problem and ended up deploying in a public gitgub repository.

    If you still need to use it, you can do one of the following:

    Add the github repository to the repositories section in your pom.xml:

    <repository>
      <id>android.support-mvn-repo</id>
      <url>https://raw.github.com/kmchugh/android.support/mvn-repo</url>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
      </snapshots>
    </repository>
    

    Then you can add the dependency as follows:

    <!-- Android Support Libraries -->
    <dependency>
      <groupId>uk.co.icatalyst</groupId>
      <artifactId>android-support-v4</artifactId>
      <version>18</version>
      <scope>compile</scope>
    </dependency>
    

    Or, fork the repository, then you can use your own URL for the repository URL.

    [Edit] I've updated the libraries, an alternative dependency would be:

    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-v4</artifactId>
      <version>18.0.0</version>
      <scope>compile</scope>
    </dependency>
    

    And for the gridlayout:

    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>gridlayout-v7</artifactId>
      <version>18.0.0</version>
      <scope>compile</scope>
    </dependency>
    
    0 讨论(0)
  • 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.

    <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] ------------------------------------------------------------------------
    
    0 讨论(0)
  • 2020-11-27 16:35

    I would recommend keep Android artefacts as part of your major MAVEN repository. Using such approach you will escape additional configurations and as a result any mishmashes. Then you will be able use simple POM files for all your client side projects.

    To do this or execute command like this:

    mvn install:install-file -DgroupId=com.google.android -Dversion=23.1.1 -Dpackaging=jar -DartifactId=support-v13 -Dfile=support-v13-23.1.1-sources.jar
    

    or just copy ./extras/android/m2repository/com/android/ into ./rootMavenRepo/com/google/android of your repository.

    0 讨论(0)
提交回复
热议问题