App级Gradle同步失败:无法解析com.google.firebase:firebase-core:15.1.0
解决Firebase依赖同步失败:
Failed to resolve: com.google.firebase:firebase-core:15.1.0 我来帮你搞定这个Gradle同步的问题~你在添加Firebase Auth和Play Services Auth依赖后遇到的报错,核心原因是Firebase组件版本不统一,结合你的配置,给你一步步拆解解决方案:
问题根源
从Firebase 15.x版本开始,官方强制要求所有Firebase SDK组件必须使用相同的主版本号,否则会触发依赖解析冲突。看你的app级build.gradle,你同时混用了不同版本的Firebase组件:
firebase-core:15.1.0firebase-auth:15.1.0firebase-database:15.0.1
版本不一致导致Gradle无法正确匹配依赖,进而抛出找不到firebase-core:15.1.0的错误。
解决方案
1. 统一所有Firebase SDK版本
把所有Firebase相关依赖的版本统一成同一个号,比如你提到的可解决问题的15.0.2,这个版本和你用的play-services-auth:15.0.1也完全兼容。修改后的依赖块如下:
dependencies { // 统一Firebase版本为15.0.2 implementation 'com.google.firebase:firebase-core:15.0.2' implementation 'com.google.firebase:firebase-auth:15.0.2' implementation 'com.google.firebase:firebase-database:15.0.2' // Play Services Auth版本保持15.0.1即可,和Firebase 15.x兼容 implementation 'com.google.android.gms:play-services-auth:15.0.1' // 其他原有依赖保持不变 compile fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:cardview-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:26.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' }
2. 确认Google Services插件版本兼容
你的项目级build.gradle里配置的com.google.gms:google-services:4.0.0完全适配Firebase 15.x版本,这个配置没问题,不用修改。
3. 验证仓库配置
项目级build.gradle里已经正确添加了Google的Maven仓库(google()和maven { url "https://maven.google.com" }),确保这些仓库在repositories列表中优先级足够高,Gradle就能优先从官方仓库拉取依赖。
额外小技巧
如果同步后还是有问题,可以尝试:
- 点击工具栏的
Sync Project with Gradle Files按钮重新同步 - 执行
File -> Invalidate Caches / Restart清除缓存后再同步
内容的提问来源于stack exchange,提问作者TJay
相关产品推荐
相关产品推荐

