JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
14.85k stars 1.08k forks source link

Unable to access LocalLifecycleOwner #4749

Closed cmpeguerog closed 2 weeks ago

cmpeguerog commented 2 weeks ago

Describe the bug

java.lang.IllegalStateException: CompositionLocal LocalLifecycleOwner not present
    at androidx.lifecycle.compose.LocalLifecycleOwnerKt$LocalLifecycleOwner$1.invoke(LocalLifecycleOwner.kt:26)
    at androidx.lifecycle.compose.LocalLifecycleOwnerKt$LocalLifecycleOwner$1.invoke(LocalLifecycleOwner.kt:25)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:29)
    at androidx.compose.runtime.LazyValueHolder.getValue(ValueHolders.kt:31)
    at androidx.compose.runtime.CompositionLocalMapKt.read(CompositionLocalMap.kt:90)
    at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:2135)
        .....

Affected platforms

Versions

Expected behavior

pablichjenkov commented 2 weeks ago

That version of the lifecycle library doesn't look valid. Should be something like org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose:2.8.0-alpha01

MatkovIvan commented 2 weeks ago

You must use androidx.compose.ui.platform.LocalLifecycleOwner on Compose 1.6.

This was moved to another module (androidx.lifecycle.compose.LocalLifecycleOwner) recently in AOSP, but it won't work until Compose 1.7