Status Update
Comments
jb...@google.com <jb...@google.com> #2
To use
The issue is happening because, starting from LocalLifecycleOwner
has been moved from androidx.compose.ui
to lifecycle-runtime-compose
, as outlined in their respective release notes. For compatibility reasons, you must update both dependencies.
For context, note these changes were made to enable the utilization of its Compose-based helper APIs beyond Compose UI (such as in
If the issue persists even after updating your Compose UI, please let us know.
Edit: please see
kj...@google.com <kj...@google.com>
mk...@google.com <mk...@google.com>
mk...@google.com <mk...@google.com> #3
If this change has made both libraries version dependent, it seems that guide them to the release note so that users will not experience difficulties :)
ga...@google.com <ga...@google.com> #4
lifecycle 2.8.0 is now stable but compose UI 1.7.0 is still in beta.
sg...@google.com <sg...@google.com> #5
Same problem here. Lifecycle 2.8.0
is now stable but Compose UI 1.7.0
is still beta. Of course our Dependabot didn't know about this relationship between dependencies 😬
ga...@google.com <ga...@google.com> #6
Something like that really shouldn't happen... 🤦🏻♂️
sg...@google.com <sg...@google.com> #7
Thats really really bad. I would always expect the latest stable versions to be compatible. Please add this requirement to the changelog or better add a warning at compile time if used with incompatible combinations.
py...@squareup.com <py...@squareup.com> #8
We acknowledge that the behavior dependency between Lifecycle 2.8 Stable and Compose 1.7 Beta is not ideal. This should not have occurred, and we are working in a fix and looking into how we can prevent it in the future. We have updated our release notes to clarify this issue.
In the meantime, while Compose 1.7 Stable has not been released, we have outlined some potential workarounds below. Please note that these solutions are not perfect but they could be helpful to some of you while the fix is not ready:
-
Map
androidx.compose.ui.platform.LocalLifecycleOwner
(Compose 1.6) toandroidx.lifecycle.compose.LocalLifecycleOwner
(Lifecycle 2.8). Here's an example:CompositionLocalProvider( androidx.lifecycle.compose.LocalLifecycleOwner provides androidx.compose.ui.platform.LocalLifecycleOwner.current, ) { // ... }
- Please note that when using Navigation Compose, this may be required on each navigation page (for more details, refer to
).comment #11
- Please note that when using Navigation Compose, this may be required on each navigation page (for more details, refer to
-
Manually pass
androidx.compose.ui.platform.LocalLifecycleOwner
(Compose 1.6) to Lifecycle 2.8 methods. For instance:val state by stateFlow.collectAsStateWithLifecycle( owner = androidx.compose.ui.platform.LocalLifecycleOwner.current )
Thank you.
sg...@google.com <sg...@google.com> #10
the option 2) will not work with compose navigation component, right ? As the lib also provides a LocalLifecycleOwner
and 3) will not work for any library that uses LocalLifecycleOwner
internally.
ga...@google.com <ga...@google.com> #11
the option 2) will not work with compose navigation component, right ? As the lib also provides a
LocalLifecycleOwner
Yes, you would need to also include it on each navigation page (composable()
route).
- will not work for any library that uses
LocalLifecycleOwner
internally.
Yes.
xa...@google.com <xa...@google.com> #12
For the record, the new dropUnlessResumed
and dropUnlessStarted
APIs won't work with Navigation 2.7 out of the box. Similar to the fix above, the new LocalLifecycleOwner
needs to be explicitly assigned to the NavBackStackEntry
in every composable()
route.
composable(...) { navBackStackEntry ->
CompositionLocalProvider(
androidx.lifecycle.compose.LocalLifecycleOwner provides navBackStackEntry
) {
MyScreen(
onBackClick = dropUnlessResumed { navController.popBackStack() }
)
}
}
ga...@google.com <ga...@google.com> #13
Branch: androidx-main
commit 5d638420d6b6f3df21e4c1cb7c9e48566c1dcafe
Author: Marcello Galhardo <mgalhardo@google.com>
Date: Tue May 21 19:23:41 2024
Add version constraint to Compose UI 1.7.0-beta01 in Lifecycle
RelNote: "`lifecycle-runtime-compose` now has a version constraints with Compose UI 1.7.0-beta01"
Fixes:
Test: Manual
Change-Id: I25dfd4100a4d3bd2f0f32f21711b95e987e2ff2a
M lifecycle/lifecycle-runtime-compose/build.gradle
ga...@google.com <ga...@google.com>
il...@google.com <il...@google.com> #14
val orderLines by viewModel.orderLines.collectAsStateWithLifecycle(
lifecycleOwner = androidx.compose.ui.platform.LocalLifecycleOwner.current
)
to...@gmail.com <to...@gmail.com> #15
to...@gmail.com <to...@gmail.com> #16
hu...@google.com <hu...@google.com> #17
The ./gradlew app:dependencies --configuration releaseRuntimeClasspath
I couldn't find any Compose library resolved to alpha versions, the highest version was 1.6.5.
Is the statement correct? Or do I misinterpret it?
hu...@google.com <hu...@google.com> #18
@
Lifecycle does not have a transitive dependency on Compose since it's not strictly related to Compose. It's more like Compose 1.7 has been adjusted to Lifecycle 2.8.0. So you need to explicitly update your Compose dependencies.
hu...@google.com <hu...@google.com> #19
lifecycle-runtime-compose
2.8.* does not explicitly depend on compose-ui
1.7.* but there is a behavior compatibility issue between the versions - meaning standard POM dependency version checks will not detect the problem.
To understand the issue better, let’s go step by step on what happened:
- We have introduced a new
LocalLifecycleOwner
insidelifecycle-runtime-compose
. - We have inverted the dependency between
compose-ui
andlifecycle-runtime-compose
.- Before:
lifecycle-runtime-compose
- depends on ->compose-ui
. - After:
compose-ui
- depends on ->lifecycle-runtime-compose
.
- Before:
- We have changed the “old”
LocalLifecycleOwner
fromcompose-ui
to return the new one inlifecycle-runtime-compose
for binary compatibility.compose-ui
1.6.*, sets up the “old”LocalLifecycleOwner
at runtime.compose-ui
1.7.*, sets up the “new”LocalLifecycleOwner
at runtime.
lifecycle-runtime-compose
2.7.* needs the “old”LocalLifecycleOwner
.lifecycle-runtime-compose
2.8.* needs the “new”LocalLifecycleOwner
.
Now, when combining compose-ui
1.6.* and lifecycle-runtime-compose
2.8.* or compose-ui
1.7.* and lifecycle-runtime-compose
2.7.*, they will reference to different LocalLifecycleOwner
instances at runtime.
Since there's no direct dependency between them, standard POM checks cannot detect this issue. A call chain analysis would have been required to identify the behavior incompatibility between stable versions.
z-...@unext.jp <z-...@unext.jp> #20
hu...@google.com <hu...@google.com> #21
Branch: androidx-main
commit 59dd212495f4378911cbb310367743b2aae734a3
Author: Marcello Galhardo <mgalhardo@google.com>
Date: Wed May 29 17:49:02 2024
Make `LocalLifecycleOwner` backward compatible with Compose 1.6.*
Lifecycle 2.8.* requires Compose 1.7.* for correctness, but
Compose 1.7.* have not yet reached stable.
For allowing Lifecycle 2.8.* to be used with Compose 1.6.*, we are
introducing the following measures:
* When Lifecycle 2.8.* detects it's running with Compose 1.6.*, it
uses reflection to access the previous version of
`androidx.compose.ui.platform.LocalLifecycleOwner`.
* A custom Proguard rule has been added to prevent the obfuscation of
`androidx.compose.ui.platform.LocalLifecycleOwner` when using
Compose 1.6.*. This ensures the reflection approach works correctly.
We have tested these backward compatibility measures in various
scenarios, including:
* Projects with and without Navigation Compose integrated.
* Compose versions 1.6.* and 1.7.*.
* Builds both with and without Proguard obfuscation applied.
Please note that backward compatibility reflection will be removed once
Compose 1.7.* is stable. A Gradle dependency constraint should be
put in place to ensure smooth migration for clients.
Fixes:
Test: manual
Change-Id: I3d0666a88eb309aae9a5c60eacc6818f52dd0bfd
M lifecycle/lifecycle-runtime-compose/build.gradle
A lifecycle/lifecycle-runtime-compose/proguard-rules.pro
A lifecycle/lifecycle-runtime-compose/src/androidMain/kotlin/androidx/lifecycle/compose/LocalLifecycleOwner.android.kt
M lifecycle/lifecycle-runtime-compose/src/commonMain/kotlin/androidx/lifecycle/compose/LocalLifecycleOwner.kt
A lifecycle/lifecycle-runtime-compose/src/desktopMain/kotlin/androidx/lifecycle/compose/LocalLifecycleOwner.desktop.kt
hu...@google.com <hu...@google.com> #22
Looking at the
Description
Lifecycle: 2.5.0-alpha01 - 2.5.0-beta01
Devices/Android versions reproduced on: Emulator & various tablets 5.0 - 11.
If this is a bug in the library, we would appreciate if you could attach:
Anything with a minsdk under API 24 will cause the crash. So it somehow ties into the Java 8, desugaring, and Kotlin interface default methods I think.
Seehttps://github.com/square/leakcanary/issues/2314 for extra details.