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
相关产品推荐
相关产品推荐

