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

如何解决Gradle插件版本不兼容导致的Flutter构建失败问题?

解决Kotlin Gradle Plugin版本不兼容问题

步骤1:统一项目Kotlin版本

打开项目根目录下的android/build.gradle文件,修改或添加ext.kotlin_version为满足要求的版本(建议选1.7.20这类稳定版,需和你的Android Gradle插件版本匹配,比如AGP 7.x系列对应Kotlin 1.5.20及以上):

buildscript {
    ext.kotlin_version = '1.7.20'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.4.2" // 确保AGP版本与Kotlin版本兼容
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

步骤2:强制所有依赖使用指定Kotlin版本

在同一个android/build.gradle文件的allprojects块中,添加版本强制策略,覆盖依赖自带的旧版本:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    configurations.all {
        resolutionStrategy {
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
        }
    }
}

步骤3:清理缓存并重新构建

执行以下命令完成清理和重新构建:

flutter clean
flutter pub get
cd android && ./gradlew clean assembleDebug

如果问题仍存在,检查pubspec.yaml中wakelock的版本是否过旧,手动指定最新稳定版(如0.6.2)后,再重复上述清理构建步骤。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 19:32:05