1

I updated a project from Jetpack compose 1.0.0 to 1.2.1. Therefore I increased the version to 1.2.1 for following dependencies:

    // ***** UI & Jetpack Compose *****
    implementation("androidx.compose.ui:ui:${SharedVersions.jetpackCompose}")
    // ViewBinding support to integrate xml views via AndroidView()
    implementation("androidx.compose.ui:ui-viewbinding:${SharedVersions.jetpackCompose}")
    // Tooling support (Previews, etc.)
    implementation("androidx.compose.ui:ui-tooling:${SharedVersions.jetpackCompose}")
    // Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
    implementation("androidx.compose.foundation:foundation:${SharedVersions.jetpackCompose}")
    // Material Design
    implementation("androidx.compose.material:material:${SharedVersions.jetpackCompose}")
    // Integration with observables
    implementation("androidx.compose.runtime:runtime-livedata:${SharedVersions.jetpackCompose}")
    implementation("androidx.compose.runtime:runtime-rxjava2:${SharedVersions.jetpackCompose}")

and set

    composeOptions {
        kotlinCompilerExtensionVersion = "1.3.2"
    }

Due to the dependencies/requirements of jetpack compose 1.2.1 I had to update following parts in my application to get it to compile:

compileSdk from 31 to 32
targetSdk from 31 to 32
gradle android plugin from 7.2.2 to 7.3.0
gradle 7.3.3 to 7.4.0
kotlin from 1.5.10 to 1.7.20

and minor code migrations to support update the new kotlin version.

After that the application compiles but it crashes on first start with:

ClassCastException: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function

The crash occurs when calling a function similiar to this:

fun <D> NavGraphBuilder.createAppNavGraphComposableDataAware(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    content: @Composable (backStackEntry: NavBackStackEntry, data: D) -> Unit
) {
    addDestination(Destination(provider, content as as @Composable (NavBackStackEntry, Any?) -> Unit)
}

Any clues what changed inside the jetpack compose libs or compiler? Does anyone else has problems similiar to this when using Composable Lambdas?

Sven
  • 1,648
  • 1
  • 21
  • 31
  • Have you tried checking version compatibilities? https://developer.android.com/jetpack/androidx/releases/compose-kotlin – z.g.y Oct 11 '22 at 15:28
  • 1
    I checked, according to the docs it should be compatible, we use kotlinCompilerExtensionVersion 1.3.2 and Kotlin 1.7.20 – Sven Oct 11 '22 at 15:38
  • I just tried updating my project with same compose/kotlin versions you have and it imploded, I got this issue https://stackoverflow.com/questions/73302605/creationextras-must-have-a-value-by-saved-state-registry-owner-key and led me to this github issue https://github.com/google/dagger/issues/3484, I keep getting a `navigation` thing exception and I was able to solve it by adding the latest `androidx.navigation:navigation-fragment-ktx` which is `2.5.2`, I'm not sure if this will solve yours though. Just try to have the latest `navigation-fragment-ktx` and have it included in your modules. – z.g.y Oct 11 '22 at 17:23
  • hey @Sven did you manage to solve it? I'm having the same issue :( – Dan Ponce Aug 21 '23 at 21:53
  • hi @DanPonce no, I only have a workaround to `gradlew clean` the project and recompile it. After the first recompile it works until the next update. Then I have to clean again. – Sven Aug 28 '23 at 13:34

0 Answers0