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

Flutter项目构建失败:更新Kotlin Gradle插件后仍报错求助

解决Flutter项目Kotlin Gradle插件版本不匹配问题
  • 先确认android/build.gradle的两处配置是否正确:

    1. 确保ext.kotlin_version已设置为'1.7.20':
      ext.kotlin_version = '1.7.20'
      
    2. 检查dependencies中的Kotlin插件依赖是否引用了该变量,而非硬编码旧版本:
      dependencies {
          classpath "com.android.tools.build:gradle:7.4.2"
          classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
          // 其他依赖保留原有配置即可
      }
      
  • 检查android/gradle.properties中是否存在Flutter强制指定的Kotlin版本配置,如果有,同步修改为1.7.20:

    flutter.kotlinVersion=1.7.20
    
  • 清理缓存并重新构建:

    1. 执行Gradle清理命令:
      ./gradlew clean
      
    2. 执行Flutter清理命令:
      flutter clean
      
    3. 可选:删除项目根目录下的.gradle文件夹和android/app/build文件夹,彻底清理缓存
    4. 重新构建项目:
      flutter build apk
      
  • 若仍有问题,排查第三方依赖是否硬编码了旧版Kotlin插件:
    执行命令查看依赖树,定位异常依赖:

    ./gradlew app:dependencies
    

    找到硬编码旧Kotlin版本的依赖后,通过exclude排除或升级该依赖版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 02:55:16