java - Gradle 同步失败 : com. google.android.gms :play-services-basement and com. google.firebase:firebase-common

标签 java android firebase firebase-realtime-database android-gradle-plugin

我正在尝试将 firebase 包含到我的 android 项目中,如官方 firebase 文档中所述。该应用程序非常基础,并使用 Google 的视觉 API。

我收到的错误:

Gradle sync failed: Failed to notify dependency resolution listener. The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[11.0.4,11.0.4], [15.0.1,15.0.1]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

我已经尝试过网站上发布的类似问题的一些解决方案,但这些解决方案对我不起作用。更重要的是,我想了解根本原因,而不是盲目地修改版本。

以下是我的 gradle 文件:

模块级别

apply plugin: 'com.android.application'
/* ... */    
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:2.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services:11.0.4'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

apply plugin: 'com.google.gms.google-services'

项目级别

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

正在运行./gradlew app:dependencies给出:

Failed to notify dependency resolution listener.

The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[11.0.4,11.0.4], [15.0.1,15.0.1]], but resolves to 15.0.1. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

The library com.google.firebase:firebase-common is being requested by various other libraries at [[11.0.4,11.0.4]], but resolves to 16.0.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

最佳答案

更新以下内容:

        classpath 'com.google.gms:google-services:4.0.1'

对此:

        classpath 'com.google.gms:google-services:4.1.0'

也如文档中所述:

Note: Don't use the combined play-services target. It brings in dozens of libraries, bloating your application. Instead, specify only the specific Google Play services APIs your app uses.

因此,删除此:

 implementation 'com.google.android.gms:play-services:11.0.4'

并添加具有更新版本的特定Google Play服务API,例如implementation 'com.google.android.gms:play-services-auth:16.0.1'

还将 firebase-core 更新到版本 16.0.4

查看此处了解更多信息:

https://developers.google.com/android/guides/setup


当您收到此错误时:

The library com.google.android.gms:play-services-basement is being requested by various other libraries at [[15.0.1,15.0.1]], but resolves to 16.0.1.

这意味着您在 gradle 中使用的直接依赖项(在 google maven 存储库内)正在使用传递依赖项 com.google.android.gms:play-services-basement

在本例中firebase-core:16.0.1使用play-services-basement:15.0.1以及最新版本play-services-basement16.0.1 ,因此您会收到此错误。

您还可以查看this 2018 年 10 月 2 日,他们做了以下事情:

Minor internal feature updates were made to some core libraries (play-services-auth, play-services-base, play-services-basement, play-services-flags, play-services-stats, play-services-tasks) used by other Google Play services libraries.

他们还发布了 com.google.android.gms:play-services-basement:16.0.1com.google.firebase:firebase-core:16.0.4

另请在此处查看我的答案:

Android | Cannot add all Google libraries for version 15.0.1

关于java - Gradle 同步失败 : com. google.android.gms :play-services-basement and com. google.firebase:firebase-common,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53244160/

相关文章:

java - 升级android studio后"Failed to resolve: support-v4"

android - WeightedLatLng 和集合<WeightedLatLng>

java.nio.channels.SocketChannel 用于定期写入和立即读取

java - 如何从两个 map 中删除相同的键

java - 为什么在使用 ContextWraper.getDir 创建目录时出现 app_

python - 云数据流流式传输,空闲时停止以省钱?

angular - 类型 { production : boolean; } 上不存在属性 'firebase'

java - Jar 找不到 .fxml 文件的路径

android - 在启动时调用 ActionBar 中的 onNavigationItemSelected 如何避免它?

ios - ld : framework not found after pod install