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

Flutter Release模式打包APK时遭遇Kotlin版本兼容性问题

解决Flutter Release打包Kotlin元数据版本不兼容问题
  • 统一项目Kotlin版本
    打开项目根目录下的android/build.gradle,将Kotlin版本统一为1.8.0,并确保Gradle插件版本与之兼容:

    buildscript {
        ext.kotlin_version = '1.8.0'
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.4.2' // 与Kotlin 1.8.0兼容的版本
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  • 强制所有模块使用指定Kotlin版本
    在android/build.gradle的allprojects块中添加版本强制策略,避免依赖插件使用不一致的Kotlin版本:

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
        configurations.all {
            resolutionStrategy {
                force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0"
                force "org.jetbrains.kotlin:kotlin-reflect:1.8.0"
            }
        }
    }
    
  • 排查并处理冲突插件
    运行flutter pub deps --tree查看所有依赖插件,找出使用旧版Kotlin的插件:

    • 优先更新该插件到最新版本
    • 若无法更新,在android/app/build.gradle中单独覆盖其Kotlin依赖:
      dependencies {
          implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
              force = true
          }
      }
      
  • 清理缓存后重新构建
    执行以下命令彻底清理缓存并重新打包:

    flutter clean
    cd android && ./gradlew clean
    cd .. && flutter build apk --release
    
  • 验证Gradle JDK配置
    在Android Studio中打开File > Settings > Build, Execution, Deployment > Build Tools > Gradle,确认Gradle使用的JDK版本为17(与Android Studio Koala及Kotlin 1.8.0兼容)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 17:54:57