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

Flutter构建APK时出现Kotlin版本不兼容错误求助

解决Flutter APK构建中的Kotlin版本不兼容错误

项目配置信息

pubspec.yaml 配置

version: 1.0.0+1
environment:
  sdk: '>=3.2.3 <4.0.0'
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.6
  bloc: ^8.1.2
  flutter_bloc: ^8.1.3
  flutter_svg: ^2.0.9
  google_fonts: ^6.1.0
  equatable: ^2.0.5
  mask_text_input_formatter: ^2.8.0
  flutter_secure_storage: ^9.0.0
  http: ^1.1.2
  pin_code_fields: ^8.0.1
  shimmer: ^3.0.0
  google_maps_flutter: ^2.5.3
  geolocator: ^10.1.0
  # location: ^5.0.0
  flutter_rating_stars: ^1.0.3+4
  flutter_polyline_points: ^2.0.0
  url_launcher: ^6.2.3
  intl: ^0.19.0
  googleapis: ^12.0.0
  flutter_slidable: ^3.0.1
  firebase_core: ^2.24.2
  firebase_messaging: ^14.7.10
  # overlay_support: ^2.1.0
  permission_handler: ^11.2.0

项目根目录 build.gradle 配置

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

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

    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
    
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

构建错误信息

C:/Users/azimz/.gradle/caches/transforms-3/889ce5bd12f1117e5357d5fcdb5e1305/transformed/core-1.10.1/jars/classes.jar!/META-INF/core_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

e: C:/Users/azimz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.

e: C:/Users/azimz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.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.9.0, expected version is 1.6.0.

e: C:/Users/azimz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.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.9.0, expected version is 1.6.0.

e: C:/Users/azimz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.0/cd65c21cfd1eec4d44ef09f9f52b6d9f8a720636/kotlin-stdlib-common-1.9.0.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.9.0, expected version is 1.6.0.  

解决方案

步骤1:统一Kotlin与Gradle插件版本兼容性

当前使用的Gradle插件版本是7.3.1,该版本适配Kotlin 1.8.x系列,过高的Kotlin版本会触发不兼容问题。修改项目根目录的build.gradle文件:

buildscript {
    // 修改为适配Gradle 7.3.1的Kotlin版本
    ext.kotlin_version = '1.8.20'
    repositories {
        google()
        mavenCentral()
    }

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

步骤2:清理缓存

错误来自Gradle缓存的旧版本文件,需要彻底清理:

  • 执行命令:flutter clean
  • 可选:手动删除本地Gradle缓存目录C:/Users/azimz/.gradle/caches

步骤3:重新构建

运行flutter build apk重新构建APK,验证错误是否解决。

额外说明

Gradle插件与Kotlin版本存在对应关系,后续升级时需注意匹配:

  • Gradle插件7.3.x → Kotlin 1.8.x
  • Gradle插件7.4.x → Kotlin 1.8.x/1.9.x

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 06:33:21