无法解析:com.google.firebase:firebase-core:15.0.0

19

在集成firebase时,我遇到了一个奇怪的问题:

在此输入图像描述


欢迎来到 Stack Overflow![请勿将您的代码发布为图像。] (//meta.stackoverflow.com/q/285551) - rene
1
请包含您的gradle文件内容。 很可能您没有像这里所述那样包含Google存储库: https://dev59.com/xlcO5IYBdhLWcg3whR3M - Alexander Hoffmann
6个回答

61
如果您从工具中自动集成Firebase,Android Studio的新版本会出现奇怪的错误,导致软件插入

标记。
    implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'

而不是

    implementation 'com.google.firebase:firebase-database:16.0.1'

修正此行(删除最后一个冒号后面的数字)

在此输入图片描述


3
我按照这个步骤操作了,但这并没有确认云存储已经添加到应用程序中? - CoderGirl94
3
非常感谢,我为此浪费了一天时间... 我不明白为什么谷歌会发布这样的垃圾有错版本... - kAmol

12
< p > 删除
implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'

并且仅添加

implementation 'com.google.firebase:firebase-database:16.0.1'
因为我们自行添加了版本号为 16.0.1 的库文件,然而在使用 Android Studio 中的 Firebase 插件连接后,它会添加一个新的带有版本号为 15.0.0 的库文件。因此这是不必要的。

1
但是为什么要删除15.0.0? - Prathamesh More
1
因为我们自己添加了16.0.15,而在之后使用工作室中的插件连接Firebase时,它会添加一个新的库文件15.0.0,因此不需要它。 - Subin Babu

4

步骤 1 :

在你的根 build.gradle 文件中添加仓库:

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

现在同步Gradle。这是包含Firebase repo的目录。
第二步:如果第一步不起作用
如果第一步不起作用,那可能是因为您正在离线模式下使用Gradle。如果gradle设置为离线,则Android Studio会搜索要更新的依赖关系的缓存副本并抛出错误,因为它尚未下载该文件。

转到“设置” >>“构建、执行、部署” >>“Gradle”。
在“全局Gradle设置”部分中,禁用“离线”模式。
现在再次同步Gradle。

1
使用 implementation com.google.firebase:firebase-database:16.0.1,就像许多人之前所写的那样。但是还要添加以下行:kapt com.google.firebase:firebase-database:16.0.1:15.0.0 这样Firebase就会保持“依赖正确设置”。

0

之后

implementation com.google.firebase:firebase-database:16.0.1
kapt 'com.google.firebase:firebase-database:16.0.1:15.0.0'

添加kapt,这对我有用


配置失败,用时0秒 在类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象上找不到方法kept()的参数[com.google.firebase:firebase-database:16.0.1:15.0.0]。 - kAmol

0

将所有依赖项更新至

dependencies {
  implementation "com.google.android.gms:play-services-base:16.0.1"
  implementation 'com.google.android.gms:play-services-maps:16.0.0'
  implementation 'com.google.android.gms:play-services-location:16.0.0'
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:28.0.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  implementation 'com.google.firebase:firebase-core:16.0.6'
  implementation 'com.google.firebase:firebase-auth:16.0.1'
  implementation 'com.google.firebase:firebase-database:16.0.5'
}

然后进行构建 -> 清理项目,构建 -> 重新构建项目,就可以正常工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接