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

Android Studio Dolphin RC1中Firebase Firestore配置:classpath放置位置

Android Studio Dolphin版本Firebase Google Services插件配置位置解决方案

针对你遇到的新版本Gradle项目结构下的配置问题,有两种可行的配置方式:

方式1:使用Gradle Plugin DSL(推荐)

这是新版本Gradle推荐的插件配置方式,步骤如下:

  1. 在项目根目录的build.gradle文件中,修改pluginManagement块,添加Google Services插件的版本声明:
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
    plugins {
        id 'com.google.gms.google-services' version '4.3.13' apply false
    }
}
  1. 打开模块级的app/build.gradle文件,在顶部的plugins块中应用该插件:
plugins {
    id 'com.android.application' // 保留你原有的应用插件
    id 'com.google.gms.google-services' // 添加这一行
}

方式2:兼容旧版classpath写法

如果你更习惯传统的classpath配置,可以在项目级build.gradle中新增buildscript块,位置可放在现有代码的任意处(示例放在最顶部):

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "TestApp"
include ':app'

之后同样需要在模块级app/build.gradle中应用插件,可选择以下任一写法:

// 旧写法
apply plugin: 'com.google.gms.google-services'

// 或者DSL写法
plugins {
    id 'com.google.gms.google-services'
}

两种方式都能完成Firebase插件的配置,优先推荐方式1,符合新版本Gradle的设计规范。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 19:24:27