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

集成Cloud Firestore SDK时com.google.gms.google-services插件未找到怎么办

这个错误的原因是你只在应用级build.gradle中声明了要使用com.google.gms.google-services插件,但没有在项目全局的Gradle配置中添加该插件的下载源和依赖声明,Gradle无法找到对应插件,按以下步骤操作即可解决:

步骤1:配置插件依赖

根据你使用的Android Studio版本不同,对应两种配置场景:

场景1:旧版项目结构(Android Studio Arctic Fox之前版本,项目根目录build.gradle包含buildscript块)

打开项目根目录下的build.gradle文件,按如下内容修改:

buildscript {
    repositories {
        // 必须添加google仓库
        google()
        mavenCentral()
    }
    dependencies {
        // 保留你原有其他classpath配置,添加下面这行
        classpath "com.google.gms:google-services:4.3.15"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

场景2:新版项目结构(Android Studio Arctic Fox及以后版本,用settings.gradle管理仓库)

首先打开项目根目录下的settings.gradle文件,确认pluginManagement和dependencyResolutionManagement块中都添加了google()仓库:

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

之后二选一完成插件声明即可:

  • 方式一:在项目根目录的build.gradle中添加插件声明
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
    // 添加下面这行
    id 'com.google.gms.google-services' version '4.3.15' apply false
}
  • 方式二:直接修改你当前的应用级build.gradle,给插件指定版本
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    // 加上版本号
    id 'com.google.gms.google-services' version '4.3.15'
}

步骤2:确认配置文件位置

确认你从Firebase控制台下载的google-services.json文件,已经放到应用级模块的根目录(默认是app文件夹下,和你贴的这个应用级build.gradle同层级)。

步骤3:同步Gradle

点击Android Studio右上角的「Sync Project with Gradle Files」按钮,等待同步完成即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 15:24:03