Guilherme Delgado
11/24/2024, 1:07 PMUnresolved reference
error for the following imports:
import androidx.compose.ui.window.ComposeUIViewController
import platform.UIKit.UIViewController
I’ve tried specifying the required .jar
files and plugins containing these references using the classpaths
and pluginClasspaths
variables from KotlinCompilation
, but the issue persists. Here’s the packages I’m referencing:
JARs:
• org.jetbrains.compose.runtime
• org.jetbrains.compose.ui
Gradle Plugins:
• org.jetbrains.compose
• org.jetbrains.kotlin.multiplatform
• org.jetbrains.kotlin.plugin.compose
I managed to resolve all other missing references, but these two remain problematic. Interestingly, if I don’t use useKsp2()
and set the languageVersion
to 1.9, the tests pass without any Unresolved reference
issues.
Could you help me understand why this happens and how to fix it? Thanks!ralf
11/24/2024, 11:16 PMGuilherme Delgado
11/25/2024, 10:51 AMExpected :OK
Actual :COMPILATION_ERROR
Because of a few, ex: Unresolved reference 'ComposeUIViewController'.
I use this configuration:
return KotlinCompilation().apply {
useKsp2()
usesKsp2 = precursorTools.contains("ksp2")
languageVersion = if (!usesKsp2) "1.9" else languageVersion
...
}
and if I comment useKsp2()
it works. The references are found or they aren’t checked, I don’t know. 🤷♂️
I’m migrating from tschuchortdev/kotlin-compile-testing
to ZacSweers/kotlin-compile-testing/issues
because I could not use Kotlin 2.1.0 with tschuchortdev
, and also I’m starting to realize tschuchortdev
’s didn’t offer the capability of testing with KSP2. I thought using ksp.useKSP2=true
in the project’s root gradle.properties
would be enough but guess not.
When running the apps it works correctly (both for 2.1.0-RC2 and 2.1.0-RC2-1.0.28, KSP1 or KSP2) . It only fails with KSP2 in Tests because of the references, the code is always generated correctly.Guilherme Delgado
11/26/2024, 1:20 PMkspWithCompilation = false
.
So that’s why when using tschuchortdev/kotlin-compile-testing
this was working (it wasn’t compiling).
I’ve tested using tschuchortdev
with kspWithCompilation = true
and also ZacSweers
without useKsp2()
with languageVersion = 1.9
and kspWithCompilation = true
and both equally fail, as expected.Guilherme Delgado
11/26/2024, 1:21 PMimport androidx.compose.ui.window.ComposeUIViewController
import platform.UIKit.UIViewController
Which I believe they are inside .klib
files 😕Guilherme Delgado
11/26/2024, 1:23 PMFile("~/.konan/kotlin-native-prebuilt-macos-aarch64-2.1.0-RC2/klib/platform/ios_simulator_arm64/org.jetbrains.kotlin.native.platform.UIKit/default/linkdata/package_platform.UIKit/04_UIKit.knm")
File("~/.gradle/caches/modules-2/files-2.1/org.jetbrains.compose.ui/ui-uikitsimarm64/1.7.1/6314e65b9b0f9dc7e0a5fdd70256def5ffb4377c/ui.klib!/default/linkdata/package_androidx.compose.ui.window/1_window.knm")
Can’t find a way to add them in the classpath 🤔Guilherme Delgado
11/26/2024, 1:51 PMalias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.compose.compiler)
implementation(compose.runtime)
implementation(compose.ui)
but continues to fail 🤷♂️Guilherme Delgado
11/26/2024, 3:16 PMralf
11/26/2024, 4:55 PMGuilherme Delgado
11/26/2024, 4:56 PMGuilherme Delgado
11/27/2024, 5:31 PMprivate val dummySourceA = """
package androidx.compose.ui.window
import androidx.compose.runtime.Composable
import platform.UIKit.UIViewController
fun ComposeUIViewController(content: @Composable () -> Unit): UIViewController = UIViewController()
""".trimIndent()
private val dummySourceB = """
package platform.UIKit
open class UIViewController
""".trimIndent()
val compilation = prepareCompilation(kotlin("Screen.kt", code), kotlin("ComposeUIViewController.kt", dummySourceA), kotlin("UIViewController.kt", dummySourceB))
will compile.
So, I have 2 options until the library supports KMP, either comment
assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode)
or use this dummy data 😅