Difference between google() and maven { url 'https://maven.google.com' }
The google()
repository is a shortcut to Google's maven repository. It was introduced in Gradle 4.x+. The actual repository URL used is `"https://dl.google.com/dl/android/maven2/" as specified here. https://maven.google.com actually points to the same repository.
However, if you are planning to use the google()
shortcut, you need Gradle 4.x+, Android Studio 3.x+ and Gradle plugin for Android 3.x+.
What is the difference between google() and mavenCentral() in project level gradle file in an android project?
They're different Maven artifact repositories, hosted by different entities, with different purposes.
google()
is Google's official Maven repository, where we host Google first-party libraries. This includes the AndroidX libraries, Jetpack Compose, Firebase, Play Services, Material, etc. You can browse what's hosted there online here.
Maven Central is hosted by Sonatype, and allows anyone to upload their projects' artifacts to it. You can read about how to publish there here and search the repository here.
Why does the Google maven repository exist and when should I use it?
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 for26.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.
Difference among mavenCentral(), jCenter() and mavenLocal()?
Actually, all 3 are Maven repository. We use these maven repositories to our build by using its URL address or its location in the local file system.
By using URL:
repositories {
maven { url("https://plugins.gradle.org/m2/") }
}
By using local file system:
repositories {
maven { url '../maven-repo' }
}
Gradle has three “aliases” which we can use when we are adding Maven repositories to our build. These aliases are:
- mavenCentral():
The mavenCentral() alias means that dependencies are fetched from the central Maven 2 repository.
repositories {
mavenCentral()
}
The URL used to access this repository is https://repo.maven.apache.org/maven2/. The name of the repository is MavenRepo.
- jcenter():
The jcenter() alias means that dependencies are fetched from the Bintray’s JCenter Maven repository
- mavenLocal():
The mavenLocal() alias means that dependencies are fetched from the local Maven repository.
Resource Link:
Gradle: Dependency Management
Maven RepositoryHandler
Jcenter vs. mavenCentral
jcenter() and mavenCentral() is a repository for the Gradle plugin in Android Studio
Earlier versions of Android Studio used mavenCentral(), and after some time, it switched to jcenter.
This is because jcenter() is superior to mavenCentral() in terms of performance and memory footprint:
- Jcenter is the world's largest Java repository
- Jcenter through the CDN service, using the https protocol, highly
secured, and Android Studio 0.8 version mavenCentral() using the http
protocol - Jcenter is a superset of mavenCentral, including many additional
jars - Jcenter performance is better than mavenCentral
- mavenCentral will automatically download many IDE-related indexes,
and these are used less often which are not required.
Resource Link:
https://www.jianshu.com/p/bce437eeb3d3
Last Update: Into the Sunset on May 1st: Bintray, JCenter, GoCenter, and ChartCenter
Update: 24-02-2021 of Android Developers Page:
Announcement Link: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Maven Central Link: https://maven.apache.org/repository/index.html
Work Around:
repositories {
mavenLocal()
// jcenter() // <- remove it
mavenCentral() // <- add it
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.spring.io/plugins-release/" }
}
Maven API search doesn't retrieve Google dependcies
You need to add the Google maven repository, update your settings.xml file to include it as:
<repository>
<id>google</id>
<url>https://maven.google.com/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
or your build.gradle file:
repositories {
google()
}
mvnrepository.com does detail where the dependency is available, if you revisit the url, it does detail it just above the 'Compile Dependencies' section
To programmatically search 'Google's Maven Repository', you can search the group-index.xml for the artifact you are looking for via https://maven.google.com/group_path/group-index.xml
So in your case you would search:
https://maven.google.com/com/google/android/gms/group-index.xml
To get the release data (pom or aar) for your chosen artifact/version, you can do a GET using the following syntax: https://maven.google.com/group_path/library/version/library-version.ext
(where ext is pom or aar)
So in your case you would do a GET for:
https://maven.google.com/com/google/android/gms/play-services-plus/16.0.0/play-services-plus-16.0.0.pom
or
https://maven.google.com/com/google/android/gms/play-services-plus/16.0.0/play-services-plus-16.0.0.aar
How to add an additional Maven repository to Android Studio build
Artic Fox started using another technique built on depedencyResolutionManagment
which introduced this head-scratching situation where the entries in the application-level build.grade
file are not searched.
What worked for me in this situation was to go into settings.gradle
(not build.gradle
and change:
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
to
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
and for good measure, I put my additional repository into settings.gradle
resulting in the following:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // WAS: FAIL_ON_PROJECT_REPOS
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven {url 'https://mvnrepository.com'} // ADDED THIS
}
}
After making these changes, the appropriate artifacts were automatically downloaded by the Android Studio standard build process.
maven { url 'https://maven.google.com' } keep disapearing from my gradle
Once i update my Android Studio to the latest version at this time (3.0) and all of its SDK Tools Packages the problem went away.
Good luck.
Allow insecure protocols, android gradle
For insecure HTTP connections in Gradle 7+ versions, we need to specify a boolean allowInsecureProtocol as true to MavenArtifactRepository
closure.
Since you have received this error for sonatype
repository, you need to set the repositories as below:
- Groovy DSL
repositories {
maven {
url "http://oss.sonatype.org/content/repositories/snapshots"
allowInsecureProtocol = true
}
// other repositories ...
}
- Kotlin DSL
repositories {
maven {
url = uri("http://oss.sonatype.org/content/repositories/snapshots")
isAllowInsecureProtocol = true
}
// other repositories ...
}
Related Topics
What Is the Use of Memoryfile in Android
Date Format Conversion Android
Error: Gradle: Execution Failed for Task ':App:Predexdebug'
Android Java.Net.Unknownhostexception: Host Is Unresolved (Strategy Question)
Android:Save a Bitmap to Bmp File Format
Android Retrofit Design Patterns
How to Highlight Multiple Words in Edittext
Android Studio Mailto Intent Doesn't Show Subject and Mail Body
How to Declare on UI Component in Android with Kotlin
Read Data from SQLite Where Column Name Contains Spaces
Android JSON Parsing of Multiple JSONobjects Inside JSONobject
Android Gps Incorrect Location Data on Query
How to Combine One Android Studio Project into Another Android Studio Project
Android - Viewrootimpl$Calledfromwrongthreadexception
Why Does My Compare Method Throw Exception -- Comparison Method Violates Its General Contract!