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
15.28k stars 1.11k forks source link

Update Lifecycle Runtime Compose to 2.8.2 #5047

Closed blakelee closed 12 hours ago

blakelee commented 2 days ago

The Jetbrains version of the lifecycle library depends on Android's lifecycle 2.8.0. Version 2.8.2 fixes some annoying issues with the LocalLifecycleOwner. I'm requesting that we update Jetbrains lifecycle to 2.8.2 to match the Android version.

Affected platforms

Versions

Here's the Google issue tracker fix of it https://android-review.googlesource.com/c/platform/frameworks/support/+/3096018

The issue was seen in a standard UI test similar to this https://github.com/square/leakcanary/issues/2677

MatkovIvan commented 2 days ago

but this is a Jetbrains issue to update the binary that includes the fix

We're redirecting original Google's binaries on Android, it allows avoiding conflicts with Android-only libraries and update that part in project independently. Just add a patched Google dependency to your androidMain sourceset.

PS There is 2.8.3 with proper ProGuard rules for that compatibility reflection hack.

blakelee commented 2 days ago

Neat, so if I'm following correctly I can just do something like this? I'm not seeing a 2.8.3 anywhere yet, I'm not as familiar with the android.googlesource.com for finding these things. Hopefully this post will help out others that are struggling with the same issue.

kotlin {
  ...
  sourceSets {
    commonMain.dependencies {
      implementation("org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose:2.8.0")
    }
    androidMain.dependencies {
     implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.2")
    }
  }
}

Does adding the Android dependencies for other things also work? I'm assuming as long as the Kotlin version and Compose compiler are the same I can just put other updated libraries in androidMain.

MatkovIvan commented 12 hours ago

Does adding the Android dependencies for other things also work?

It will work for JetBrains' multiplatform adoptions of compose/lifecycle/navigation. It works because we don't even re-build android and uses redirection to Google's binaries on platforms where supported. Aside of independent applying of patches, it allows using Android-only libraries with these dependencies without issues like "Duplicate class declarations".