我的带有 SQLDelight DB 的 Compose 多平台项目在没有kotlinx-atomicfu插件的情况下无法构建,但当它处于活动状态时,它会与sqldelight插件发生冲突。同时,我可以在模拟器上运行它,因此问题仅在重建过程中出现。
一开始我收到本主题中提到的错误
e: java.lang.IllegalStateException: e: Could not find "../shared/build/kotlinTransformedMetadataLibraries/commonMain/org.jetbrains.kotlinx-atomicfu-0.17.3-nativeInterop-8G5yng.klib" in [/Users/<user>/Library/Application Support/kotlin/daemon]
解决方案是在顶级 build.gradle.kts 中添加几行并具有kotlinx-atomicfu依赖项
buildscript {
dependencies {
// Use the same version in the error
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.17.3")
}
}
allprojects {
apply(plugin = "kotlinx-atomicfu")
}
Run Code Online (Sandbox Code Playgroud)
添加此块后,构建会继续进行,但随后会失败,并在共享/iosMain 的MainViewController 中出现多个错误
package com.user.kmmtutorial
import androidx.compose.ui.window.ComposeUIViewController
fun MainViewController() = ComposeUIViewController {
App()
}
Run Code Online (Sandbox Code Playgroud)
错误:
ERROR: Exception while analyzing expression in (6,5) in ../shared/src/iosMain/kotlin/com/user/kmmtutorial/MainViewController.kt
Attachments:
causeThrowable
java.lang.NullPointerException
at androidx.compose.compiler.plugins.kotlin.ComposeFqNamesKt$makeComposableAnnotation$1.getType(ComposeFqNames.kt:148)
(...)
Exception while …Run Code Online (Sandbox Code Playgroud)