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

Flutter(Kotlin DSL)集成Firebase Android时Gradle任务assembleDebug失败求助

Flutter(Kotlin DSL)集成Firebase Android时Gradle任务assembleDebug失败求助

最近几天我在Flutter项目中集成Firebase Android时遇到了一个头疼的构建错误,Web端集成Firebase一切正常,但只要关联Firebase Android就会触发以下Gradle构建失败:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':firebase_core:compileDebugJavaWithJavac'.
> Cannot query the value of this provider because it has no value available.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 8m 37s
Running Gradle task 'assembleDebug'... 518.4s
Error: Gradle task assembleDebug failed with exit code 1

我已经尝试了各种方法,但都没能解决问题:

  • 更新了项目中所有依赖包到最新版本
  • 升级了Flutter和Android Studio至当前可用的最新版本
  • 删除了项目内的android/.gradle目录
  • 删除了Windows用户目录下的.gradle文件夹
  • 执行了flutter clean、flutter pub get命令
  • 改用实体安卓设备替代模拟器进行测试
  • 创建了全新的Flutter项目并关联全新的Firebase项目
  • 在Gradle配置中手动指定了ndkVersion
  • 尝试将Kotlin DSL替换为Groovy DSL配置
  • 在系统环境变量中配置了JDK 17的JAVA_HOME路径
  • 切换到其他网络环境重新构建

我还试过用AI工具查找解决方案,也看了不少YouTube上的Flutter集成Firebase教程,但要么是针对Mac系统的,要么教程版本太老,对当前问题没帮助。

以下是我的配置文件内容:

android/build.gradle.kts

buildscript {
    val kotlinVersion by extra("1.9.10")
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
        classpath("com.android.tools.build:gradle:8.0.2")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
        classpath("com.google.gms:google-services:4.4.3")
    }
}

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

val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
}

subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}

app/build.gradle.kts

plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services")
}

android {
    namespace = "com.example.untitled1"
    compileSdk = 36
    ndkVersion = "27.0.12077973"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17.toString()
    }

    defaultConfig {
        minSdk = 23
        targetSdk = 34
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    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.getByName("debug")
        }
    }
}

flutter {
    source = "../.."
}

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:32.1.0"))
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-firestore")
}

pubspec.yaml

name: untitled1
description: "A new Flutter project."
publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: ^3.8.1

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.8
  firebase_core: ^3.15.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^5.0.0

flutter:
  uses-material-design: true

我的机器配置:i7 8代处理器,16GB DDR4内存,Windows 10 64位系统,当前使用Android Studio Narwhal版本。

希望社区的各位能帮我排查下问题所在,谢谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 13:27:58