My Compose Multiplatform project with SQLDelight DB fails to build without kotlinx-atomicfu plugin, but when it's active it clashes with sqldelight plugin. At the same time I'm able to just run it on Emulator, so the issue appears only during the rebuild process.
At the beginning I get an error mentioned in this topic
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]
The solution for it is to add several lines in a top-level build.gradle.kts with kotlinx-atomicfu dependency
buildscript {
dependencies {
// Use the same version in the error
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.17.3")
}
}
allprojects {
apply(plugin = "kotlinx-atomicfu")
}
After adding this block the build proceeds further, but then fails with several errors in MainViewController at shared/iosMain
package com.user.kmmtutorial
import androidx.compose.ui.window.ComposeUIViewController
fun MainViewController() = ComposeUIViewController {
App()
}
errors:
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)
After some investigations I found out that disabling sqldelight plugin in build.gradle.kts (:shared) makes this issue disappear, so seems like it's kind of clashing with kotlinx-atomicfu
plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
// id("com.squareup.sqldelight")
}
Summarizing: I'm able to run my Compose Multiplatform directly on Emulator, but each time I try to rebuild it it fails. So seems like I get errors without kotlinx-atomicfu plugin active, but when it's included my project fails with sqldelight plugin active. I've tried to use newer version of the sqldelight, but the most recent one uses kotlin version that is not yet supported in current Compose Multiplatform.
I've found similar issue appearing in Philipp Lackner's Compose Multiplatform tutorial, but he mentioned that this issue doesn't affect a build process