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

KMP项目编译报错:'kotlin.native.cacheKind'设为'none'求最优解

问题描述

我fork了某个KMP项目后,编译时持续触发如下错误:

* Exception is:
java.lang.IllegalStateException: Error: 'kotlin.native.cacheKind' is explicitly set to 'none'.
This option significantly slows the Kotlin/Native compiler.
Compose Multiplatform Gradle plugin manages this property automatically based on a Kotlin compiler version being used.
  * Recommended action: remove explicit 'kotlin.native.cacheKind=none' from gradle.properties. 
  * Alternative action: disable cache kind management by adding 'compose.kotlin.native.manageCacheKind=false' to your 'gradle.properties'.
    at org.jetbrains.compose.experimental.internal.ConfigureNativeCompilerCachingKt.checkExplicitCacheKind(configureNativeCompilerCaching.kt:83)
    at org.jetbrains.compose.experimental.internal.ConfigureNativeCompilerCachingKt.access$checkExplicitCacheKind(configureNativeCompilerCaching.kt:1)

官方给出的替代方案compose.kotlin.native.manageCacheKind=false并非最优解,我不愿禁用Compose的缓存管理能力,请问是否存在更好的解决办法?

最优解决方案

优先采用以下步骤解决,无需禁用Compose的缓存管理:

  • 移除根目录gradle.properties中的显式配置
    直接删除或注释掉项目根目录下gradle.properties文件里的kotlin.native.cacheKind=none这一行。Compose Multiplatform插件会根据当前Kotlin编译器版本自动适配最优缓存策略,既保证编译效率,又避免配置冲突。

  • 排查子模块的配置
    如果项目包含多模块结构,还要检查每个子模块下的gradle.properties文件,确保没有在子模块中重复配置kotlin.native.cacheKind=none。

  • 清理Gradle缓存(可选)
    修改配置后若问题仍存在,执行以下命令清理Gradle缓存,确保新配置生效:

    ./gradlew cleanBuildCache
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 07:33:16