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

Flutter打包APK报错:更新Kotlin Gradle插件后问题仍存在

Flutter打包APK时Kotlin版本更新后仍报错的解决方法

问题描述

执行flutter build apk --release命令时触发错误:

[!] Your project requires a newer version of the Kotlin Gradle plugin.                              
Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, 
then update
C:\Users\jmichelena\Desktop\Buenas\hola\android\build.gradle:                                       
ext.kotlin_version = '<latest-version>'       

已在android/build.gradle文件中将Kotlin版本更新为1.7.20,代码片段如下,但错误依旧:

buildscript {
    ext.kotlin_version = '1.7.20'
    repositories {
        google()
        mavenCentral()
    }
}

解决步骤

  • 检查Kotlin插件依赖同步:除了设置ext.kotlin_version,还要确保buildscript的dependencies块里的Kotlin Gradle插件引用了该变量,版本必须一致。建议直接升级到当前最新稳定版(比如1.9.20),示例:
    buildscript {
        ext.kotlin_version = '1.9.20'
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:7.4.2" // 注意Gradle插件版本要和Kotlin版本兼容
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  • 清理缓存重新构建:
    1. 执行命令flutter clean清理项目缓存
    2. 删除项目android/.gradle文件夹
    3. 重新运行flutter build apk --release
  • 核对Gradle版本兼容性:Kotlin版本与Android Gradle插件版本需匹配,避免混用不兼容的版本组合
  • 确认修改文件路径:确保修改的是项目根目录下的android/build.gradle,而非android/app/build.gradle

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 11:20:33