You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio集成Firebase Firestore失败:无法解析com.google.firebase:firebase-firestore:11.0.4

解决Firebase Firestore依赖无法解析的问题

我来帮你排查这个依赖解析的问题,大概率是配置环节或者版本兼容性出了问题,咱们一步步来解决:

1. 先检查项目根目录的build.gradle配置

这是很多新手容易漏掉的关键步骤——Firebase依赖必须从Google Maven仓库拉取,所以根目录的两个地方都得配置好:

buildscript {
    repositories {
        google() // 一定要添加Google官方仓库
        mavenCentral()
    }
    dependencies {
        // 这里的插件版本要和你的Firebase依赖版本匹配,11.0.4对应插件版本也是11.0.4
        classpath 'com.google.gms:google-services:11.0.4'
    }
}

allprojects {
    repositories {
        google() // allprojects里同样要配置Google仓库
        mavenCentral()
    }
}

2. 修复Module:App的版本兼容性问题

你当前用的com.android.support:appcompat-v7:27.1.1和com.google.firebase:firebase-firestore:11.0.4版本不兼容,这是导致依赖解析失败的核心原因之一:

  • 11.0.4版本的Firebase对应支持库版本是26.x系列(比如26.1.0),如果坚持用这个旧Firebase版本,需要把support库降级到匹配版本
  • 更稳妥的方式是升级Firebase依赖到和27.1.1兼容的版本,比如15.0.1,修改后的依赖代码如下:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    // 替换成兼容的Firestore版本
    implementation 'com.google.firebase:firebase-firestore:15.0.1'
}

// 务必在文件末尾添加这一行,应用Firebase插件
apply plugin: 'com.google.gms.google-services'

3. 同步并清理项目

做完上面的配置后:

  • 点击Android Studio顶部的Sync Project with Gradle Files按钮,同步所有配置
  • 如果还是报错,执行Build > Clean Project,之后再执行Build > Rebuild Project,清理缓存后重新构建

额外建议

11.0.4是非常老旧的Firebase版本,不仅兼容性差,还可能存在安全漏洞。如果项目允许,建议升级到最新稳定版本,现在Firebase提供了BOM(物料清单)来自动管理所有Firebase依赖的版本,避免版本冲突:

dependencies {
    // 先添加Firebase BOM,统一管理版本
    implementation platform('com.google.firebase:firebase-bom:32.7.0')
    // 然后直接添加Firestore依赖,不需要写版本号
    implementation 'com.google.firebase:firebase-firestore'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

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

内容的提问来源于stack exchange,提问作者sixcookies

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:26:59