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

Flutter集成Firebase时遇Kotlin版本不兼容报错求助

解决Flutter集成Firebase时的Kotlin版本不兼容问题

问题根源

你的项目存在两个核心问题:

  • 当前指定的Kotlin版本(1.7.1)过旧,与依赖的Firebase库、Android Gradle插件版本不匹配
  • 项目级build.gradle中Kotlin Gradle插件的依赖被注释,导致Gradle无法找到正确的Kotlin编译工具链

修复步骤

1. 修正项目级android/build.gradle文件

需要修改两处关键配置:

  • 将Kotlin版本升级到与Android Gradle Plugin 7.4.2兼容的稳定版(比如1.9.20)
  • 取消Kotlin Gradle插件依赖行的注释

修改后的完整代码:

buildscript {
    ext.kotlin_version = '1.9.20'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}


plugins {
    id 'com.google.gms.google-services' version '4.4.1' apply false
}

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
}

2. 清理缓存并重新构建

执行以下操作确保配置生效:

  • 在项目根目录运行命令:flutter clean
  • 重启你的开发IDE(Android Studio/IntelliJ等)
  • 运行flutter run重新编译项目

额外说明

你的应用级build.gradle配置无问题,无需修改。后续若再遇到版本兼容问题,只需保证Android Gradle Plugin与Kotlin插件版本匹配即可。

内容的提问来源于stack exchange,提问作者Jena.T

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 17:53:13