gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:19:27 28 4
gpt4 key购买 nike

我正在尝试按照官方 firebase 文档中的描述将 firebase 包含到我的 android 项目中。该应用程序非常基础,使用了 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com