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

Flutter Android构建失败:升级Kotlin版本后kotlin-stdlib转换出错

Kotlin版本升级后Dex构建失败解决方案

升级项目根目录build.gradle中的kotlin_version到1.9.10后,构建触发如下错误:

ERROR:D8: com.android.tools.r8.kotlin.H

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform kotlin-stdlib-1.9.10.jar (org.jetbrains.kotlin:kotlin-stdlib:1.9.10) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for DexingWithClasspathTransform: /Users/zionnite/.gradle/caches/transforms-3/131ce0572a85fdeb525a81595856d4eb/transformed/jetified-kotlin-stdlib-1.9.10.jar.
         > Error while dexing.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 37m 51s

解决步骤

  • 匹配AGP与Kotlin版本
    Kotlin 1.9.10需搭配AGP 8.1.x及以上版本。打开根目录build.gradle,确认com.android.tools.build:gradle版本,不匹配则同步升级。

  • 清理缓存并重构项目

    1. 执行Android Studio菜单栏Build > Clean Project
    2. 再执行Build > Rebuild Project
    3. 手动删除项目根目录的.gradle文件夹和模块下的build目录,重启Studio后重新构建
  • 临时禁用D8/R8排查问题
    在app/build.gradle的android块中添加以下配置,禁用混淆后尝试构建,排查是否为规则冲突:

    android {
        ...
        dexOptions {
            preDexLibraries false
        }
        buildTypes {
            debug {
                minifyEnabled false
                useProguard false
            }
        }
    }
    
  • 统一Kotlin相关依赖版本
    检查项目中所有Kotlin依赖(如kotlin-reflect、kotlinx-coroutines-android等),确保版本与kotlin_version一致,避免跨版本冲突。

  • 确认Java版本配置
    Kotlin 1.9.x推荐使用Java 17或11,在app/build.gradle中更新配置:

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }
        kotlinOptions {
            jvmTarget = "17"
        }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 21:33:17