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

Flutter集成Firebase遇build.gradle报错:找不到谷歌服务插件

Flutter集成Firebase时Gradle构建失败问题

报错详情

FAILURE: Build failed with an exception.

  • 报错位置:构建文件C:\Users\82102\Documents\Folder\Coding\Flutter\kyunggi_life\android\app\build.gradle第4行
  • 问题原因:未找到插件id: 'com.google.gms.google-services',该插件不在Gradle核心插件中,且插件仓库中未指定版本号

官方建议:

  • 使用--stacktrace选项获取堆栈跟踪
  • 使用--info或--debug选项获取更多日志
  • 使用--scan选项获取完整分析

构建1秒后失败,执行Gradle任务assembleDebug耗时2064ms,最终错误提示:Gradle任务assembleDebug以退出码1失败

已尝试的排查操作

  • 耗时约3小时查找解决方案,因理解不足无法应用现有方案
  • 推测问题出在app/build.gradle和android/build.gradle两个配置文件中
  • 已执行的修复尝试:
    1. 在app/build.gradle中添加ndkVersion "26.1.10909125"、apply plugin: 'com.google.gms.google-services'及任务执行顺序代码
    2. 检查android/build.gradle中的buildscript配置,确认已添加google()、mavenCentral()仓库及com.google.gms:google-services:4.3.10的classpath依赖

相关配置文件代码

app/build.gradle

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace "com.example.kyunggi_life"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion
    ndkVersion "26.1.10909125"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID
        applicationId "com.example.kyunggi_life"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'processDebugGoogleServices') {
        task.mustRunAfter 'mapDebugSourceSetPaths'
    }
}

flutter {
    source '../..'
}

dependencies {}

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

android/build.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 18:03:15