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

Flutter构建失败:Android Gradle插件要求Kotlin Gradle插件≥1.5.20

解决Flutter项目Kotlin Gradle插件版本不兼容问题

强制统一所有模块的Kotlin版本

项目根目录的build.gradle里,除了设置全局kotlin_version,还要添加一段配置强制所有依赖模块使用这个版本,避免子模块自己硬编码旧版本:

buildscript {
    ext.kotlin_version = '1.6.21'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.4.2" // 注意AGP版本要和Kotlin版本匹配
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

// 新增这段,强制所有子项目用统一Kotlin版本
subprojects {
    configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name.startsWith("kotlin-")) {
                details.useVersion rootProject.ext.kotlin_version
            }
        }
    }
}

升级flutter_native_timezone到最新版

旧版本插件可能未适配高版本Kotlin,直接在pubspec.yaml里更新依赖:

dependencies:
  flutter_native_timezone: ^2.0.0+1

执行flutter pub get拉取新版本后再尝试构建。

临时修改本地插件配置(不推荐长期使用)

如果暂时无法升级插件,可手动修改本地缓存里的插件配置:

  1. 找到插件缓存目录:~/.pub-cache/hosted/pub.dartlang.org/flutter_native_timezone-<你的版本号>/android
  2. 打开该目录下的build.gradle,把里面的kotlin_version改成1.6.21,或者直接引用根项目的版本:
ext.kotlin_version = rootProject.ext.kotlin_version

最后清除构建缓存

执行flutter clean清除旧构建缓存,再重新运行项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 07:07:10