Why aren't the Android SDK Jars in any Maven Repository?

房东的猫 提交于 2019-11-30 04:40:01

Google now has an official maven repository announced at Google IO 2017.

buildscript {
    repositories {
        maven {
          // Google Maven Repository
          url 'https://maven.google.com'
        }
    }
    ...
}

What's New in Android Support Library (Google I/O '17)
https://youtu.be/V6-roIeNUY0?t=3m34s

What's New in Android Development Tools (Google I/O '17)
https://youtu.be/Hx_rwS1NTiI?t=20m05s

Google's Maven repository
https://developer.android.com/studio/build/dependencies.html#google-maven

Migrate to the New Plugin
https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

Google blocked it. From this link:

The Android artifacts have been built and published to the Maven repository through the efforts of the Android for Maven project. Google prevented the official Android jars from being uploaded to Maven, so the, third party, Android for Maven project was started to provide an API compatible Android artifact that could be uploaded to the Maven repository. There are now artifacts for each major Android version available in the Maven repository. These are not functional, however, and only provide stubbed implementations of the API. All methods in all classes throw a runtime exception. Because an Android app runs on a device, it will never use these libraries for execution, but the API compatibility allows an app to be compiled as if it were the real library.

I found a better solution, using the common libraries delivered by SDK, I just used Android Home as repository in the pom.xml.

 <repositories>
    <repository>
        <id>com.android.support</id>
        <url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>
    </repository>
</repositories>

does work for me now.

It's possible to use the ANDROID_HOME jars by specifying a system-<dependency> with <systemPath>:

<properties>
    <android.platform>21</android.platform>
</properties>
<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>${android.platform}</version>
        <scope>system</scope>
        <systemPath>${env.ANDROID_HOME}/platforms/android-${android.platform}/android.jar</systemPath>
    </dependency>
</dependencies>

I think they are in maven central:

http://mvnrepository.com/artifact/com.google.android/android

It doesn't look like it has 3.0 yet, but it does have quite a few older revisions. You can build android projects with maven with the help of maven-android-plugin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!