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

Flutter打包APK报错:Kotlin运行时JAR版本不兼容

解决方案:Kotlin版本不兼容问题修复

1. 统一全局Kotlin版本

在android/build.gradle中强制指定项目使用的Kotlin版本,覆盖依赖库自带的版本:

buildscript {
    ext.kotlin_version = '1.7.20' // 可根据项目实际情况调整,建议选与workmanager兼容的稳定版本
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.3.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

2. 强制所有依赖使用统一Kotlin标准库

在android/app/build.gradle的dependencies块末尾添加配置,强制替换所有冲突的Kotlin库版本:

configurations.all {
    resolutionStrategy {
        force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
        force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        force "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
    }
}

注意这里的$kotlin_version要和build.gradle中定义的版本保持一致。

3. 清理缓存并重新构建

执行以下命令彻底清除旧依赖缓存,避免残留冲突:

flutter clean
rm -rf android/.gradle
flutter pub get
flutter build apk --release

4. 检查workmanager版本兼容性

如果以上方法无效,确认pubspec.yaml中workmanager的版本与当前Flutter、Kotlin版本匹配,比如指定一个稳定兼容的版本:

dependencies:
  workmanager: ^0.5.1 # 选择适配你项目环境的版本

额外排查技巧

运行flutter pub deps查看完整依赖树,定位具体哪个库引入了不同版本的Kotlin,再针对性调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 12:25:14