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

Flutter打包Release时Kotlin版本兼容问题求助

Kotlin版本兼容问题解决方案(已用1.7.10仍报错)

我查了一堆相关帖子,所有方案都让升级Kotlin版本,但我已经用上了最新的1.7.10版本,执行flutter run --release时还是弹出一堆元数据版本不兼容的错误,提示期望版本是1.5.1,实际却是1.7.1。

我的配置信息:
android/build.gradle:

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

gradle-wrapper.properties

distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

Release模式下的错误日志:

Launching lib\main.dart on SM G990B in release mode...
e: <user_files>/myApp/build/better_player/.transforms/37fbb17d8aa9e4563e70c2fce29a3240/transformed/out/jars/classes.jar!/META-INF/better_player_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/myApp/build/wakelock/.transforms/ff661fedb16e56513c66400978568e0d/transformed/out/jars/classes.jar!/META-INF/wakelock_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/myApp/build/package_info_plus/.transforms/16efc48fb788cfa9881facf70e028d76/transformed/out/jars/classes.jar!/META-INF/package_info_plus_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/myApp/build/workmanager/.transforms/d96e0ff60c09a3780329e98266bf5470/transformed/out/jars/classes.jar!/META-INF/workmanager_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/myApp/build/flutter_image_compress/.transforms/7fd7cbac29954654e675e8bdd94e5277/transformed/out/jars/classes.jar!/META-INF/flutter_image_compress_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.7.10/d70d7d2c56371f7aa18f32e984e3e2e998fe9081/kotlin-stdlib-jdk8-1.7.10.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.7.10/1ef73fee66f45d52c67e2aca12fd945dbe0659bf/kotlin-stdlib-jdk7-1.7.10.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/.gradle/caches/modules-2/files-2.1/androidx.annotation/annotation/1.5.0/857678d6b4ca7b28571ef7935c668bdb57e15027/annotation-1.5.0.jar!/META-INF/annotation.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.7.10/d2abf9e77736acc4450dc4a3f707fa2c10f5099d/kotlin-stdlib-1.7.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
e: <user_files>/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.7.10/bac80c520d0a9e3f3673bc2658c6ed02ef45a76a/kotlin-stdlib-common-1.7.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.

可行解决步骤:

  • 更新依赖插件:针对日志里提到的better_player、wakelock、package_info_plus等Flutter插件,去pub.dev查看它们的最新版本,确保这些插件已经适配Kotlin 1.7.x。在pubspec.yaml里把这些包升级到最新版后,执行flutter pub get。
  • 清理Gradle缓存:进入项目的android/目录,执行./gradlew clean(Windows系统用gradlew clean),或者直接删除项目根目录的.gradle文件夹和build文件夹,彻底清除旧的编译残留文件。
  • 全局统一Kotlin版本:检查android/app/build.gradle里是否单独指定了更低的Kotlin版本,如果有,改成和根目录build.gradle一致的1.7.10。还可以在根目录build.gradle的allprojects块中添加配置,强制所有模块使用统一的Kotlin版本:
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
        configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'org.jetbrains.kotlin') {
                    details.useVersion '1.7.10'
                }
            }
        }
    }
    
  • 检查Gradle兼容性:当前Gradle插件7.1.3和Kotlin 1.7.10是兼容的,但如果问题依旧,可以尝试升级Gradle插件到7.2.x或更高版本,同时对应调整gradle-wrapper.properties中的Gradle版本。
  • IDE清理缓存:如果使用Android Studio,点击File -> Invalidate Caches... -> Invalidate and Restart,重启IDE后重新构建项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 14:30:58