ngh*_*253 5 android gradle kotlin kotlin-multiplatform
我的带有 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 analyzing expression in (6,5) in ../shared/src/iosMain/kotlin/com/user/kmmtutorial/MainViewController.kt
at org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext.analyzeArgumentWithFixedParameterTypes(ConstraintSystemCompletionContext.kt:54)
(...)
expression.kt
File name: MainViewController.kt Physical: true Injected: false
fun MainViewController() = ComposeUIViewController {
<caret>App()
}
org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Exception while analyzing expression in (6,5) in ../shared/src/iosMain/kotlin/com/user/kmmtutorial/MainViewController.kt
at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:253)
org.jetbrains.kotlin.util.KotlinFrontEndException: 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)
Run Code Online (Sandbox Code Playgroud)
经过一番调查后,我发现在build.gradle.kts (:shared)中禁用 sqldelight 插件会使这个问题消失,所以看起来它与kotlinx-atomicfu发生了冲突
plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
// id("com.squareup.sqldelight")
}
Run Code Online (Sandbox Code Playgroud)
总结:我可以直接在模拟器上运行我的 Compose Multiplatform,但每次我尝试重建它时都会失败。因此,似乎在没有kotlinx-atomicfu插件处于活动状态的情况下我会遇到错误,但是当包含它时,我的项目会因sqldelight插件处于活动状态而失败。我尝试使用较新版本的sqldelight,但最新版本使用当前 Compose Multiplatform 尚不支持的 kotlin 版本。
我发现Philipp Lackner 的 Compose Multiplatform 教程中出现了类似的问题,但他提到这个问题不会影响构建过程
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |