Why does the Google maven repository exist and whe

2019-04-28 18:43发布

问题:

So I found myself scratching my head as I was trying to update my build.gradle dependencies. The com.android.support:appcompat library version 26.0.2 didnt resolve. After a bit of searching I learned that I had to add Google's maven repository to the list of repositories in my project gradle file. So now both Google's maven repository and jcenter() is listed.

So why is Google now hosting their own maven repository and is there any reason not to use it? Its odd that libraries are hosted both places with different versions.

回答1:

There are several repositories in play when building an Android app:

  • jcenter() is used for a multitude of open source libraries, including the Android Plugin for Gradle.

  • google() (a.k.a., maven.google.com) is used for the support libraries, Architecture Components, and so on. For the support libraries, you need to use this repository for 26.0.0 and higher.

  • The Android Repository, installed on your hard drive by the SDK Manager, is for the support libraries prior to the introduction of maven.google.com.

  • Many other hosted repositories (jitpack.io, my CWAC repository, etc.).

Its odd that libraries are hosted both places with different versions.

I don't know if maven.google.com also supports the library versions from the Android Repository. Otherwise, roughly speaking, maven.google.com is the new hosted version of what had been the Android Repository, for newer versions of the libraries going forward.

I'm also uncertain if the Google Repository installed by the SDK Manager for the Play Services dependencies is being supplanted by maven.google.com.

why is Google now hosting their own maven repository

You would have to ask Google. The Android Repository was OK for simple builds but got to be a pain in more complex scenarios (e.g., builds on a headless CI server). Using an ordinary hosted Maven repository should simplify those things.

The template project generated by Android Studio didnt add Google's maven repository

You are using Android Studio 2.3.3 or older. Android Studio 3.0 and higher's templates will add google() for you.