Hi all! Does anyone know what may be causing the b...
# compose-desktop
g
Hi all! Does anyone know what may be causing the below error? I have spent quite a bit of time trying to fix it with no luck.
Copy code
BookListScreenRootTest[desktop] > bookListScreenRoot_displaysSearchBar[desktop] FAILED                                                                                                                                                                                                                                                   
    java.lang.NoSuchMethodError at ComposeUiTest.skikoMain.kt:221
a
What is the method it doesn’t find?
g
@Alexander Maryanovsky Seems to be CanvasLayersComposeScene
a
Try cleaning caches and rebuilding.
g
Cleaned IntelliJ cache and gradle cache. Same issue
Whats weird is that the app runs fine. It's only the tests that are failing when I run
./gradlew :composeApp:desktopTest
. I checked the dependencies and both desktopMain and desktopTest have the same dependencies. Except desktop test has the additional test libraries.
a
Maybe those additional libraries are pulling in an unexpected version of compose tests
Try the gradle task that gives you the dependency tree
g
@Alexander Maryanovsky For some reason you can see below that the compose runtime for desktop is going from 1.7.3 to 1.8.0-beta02. I am not specifying 1.8.0-beta02 anywhere. I think this may be the problem. Any idea how to get that to stop happening?
a
There’s a gradle task that shows you the dependency tree
I’m not at the computer and don’t remember its exact name, but it should tell you where the dependency came from.
g
Thats the task I ran to get the above screenshot. But here is the output to the console. It says its parent is material android is 1.7.6. THen its top level parent is desktop-jvm-windows-x64 1.7.3.
Why is 1.7.3 defaulting some of its children to 1.8.0-rc02
a
The arrow means it was upgraded because some other dependency required a higher version
Look for a requirement without an arrow
g
After dropping down several versions it seems to now be fixed. But I'm now getting this error since I am using
collectAsStateWithLifecycle
in my components.
Copy code
CompositionLocal LocalLifecycleOwner not present
java.lang.IllegalStateException: CompositionLocal LocalLifecycleOwner not present
	at androidx.lifecycle.compose.LocalLifecycleOwnerKt$LocalLifecycleOwner$1.invoke(LocalLifecycleOwner.nonAndroid.kt:28)
	at androidx.lifecycle.compose.LocalLifecycleOwnerKt$LocalLifecycleOwner$1.invoke(LocalLifecycleOwner.nonAndroid.kt:27)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:83)
	at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:46)
	at androidx.compose.runtime.LazyValueHolder.readValue(ValueHolders.kt:48)
	at androidx.compose.runtime.CompositionLocalMapKt.read(CompositionLocalMap.kt:91)
	at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:2375)
	at androidx.lifecycle.compose.FlowExtKt.collectAsStateWithLifecycle(FlowExt.kt:182)
@Alexander Maryanovsky Do you know if there is a way to provide LocalLifecycleOwner in KMP common tests? Been doing some research but have not found anything that works.
a
You can’t just
Copy code
CompositionLocalProvider(LocalLifecycleOwner provides ...) {}
it?
g
That worked, I also needed to create a TestLocalLifecycleOwner that extends LifecycleOwner. Then do
Copy code
CompositionLocalProvider(
                    LocalLifecycleOwner provides TestLifecycleOwner()
                ) { ... }
After that I got an error that
androidx.composeui:ui-util
should be replaced with the jetbrains version. To fix that I did
Copy code
configurations.named("desktopTestImplementation") {
    exclude(group = "androidx.compose.ui", module = "ui-util")
}
And finally the tests run.
a
Something is unusual in your project. There’s no reason you should have to jump through all these hoops to get tests to run
g
I shared my toml and build.gradle.kts. Could be im pulling in too many android libraries into my common source sets.
But I don't know what would replace them.