maven { url 'https://maven.google.com' } VS google()

Android studio shows Could not find runtime.aar (android.arch.lifecycle:runtime:1.0.0)., as suggested, add maven { url 'https://maven.google.com' } to file build.gradle(project level):

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
        google()
    }
...
}

The weird thing is google() already exists in the gradle file.
As the document:

MavenArtifactRepository google()
Adds a repository which looks in Google's Maven repository for dependencies.
The URL used to access this repository is "https://dl.google.com/dl/android/maven2/".

Examples:

 repositories {
     google()
 }
 
Returns:
the added resolver
Since:
4.0

Seems google() is the same as maven { url 'https://maven.google.com' } as long as:

  • Gradle 4.0 and later
  • Android Studio 3.0 and later
  • Gradle plugin for android 3.0 and later
    Anyway, it’s weird since I’m sure all the three options are satisfied, but maven { url 'https://maven.google.com' } works while google() not.
    In general maven { url 'https://maven.google.com' } is somehow a better choice than google().

Found something:

It’s actually not something to do with maven { url 'https://maven.google.com' } or google(), but something else.
These two situations will fail:

allprojects {
    repositories {
        jcenter()
        google()
    }
...
}
allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
...
}

Meanwhile these two situations will pass:

allprojects {
    repositories {
        google()
        jcenter()
    }
...
}
allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
...
}
    原文作者:JaedenKil
    原文地址: https://www.jianshu.com/p/079a76c6d312
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞