Android Composables not transformed by compiler in 1.6.10
Describe the bug
After updating from CMP 1.6.2 to 1.6.10, Android functions (at least ComponentActivity.setContent from activity-compose and ComposeContentTestRule.setContent from ui-test-junit4) aren't getting transformed by the Compose compiler.
If I call either of those setContent functions I get a NoSuchMethodError:
java.lang.NoSuchMethodError: 'void androidx.compose.ui.test.junit4.ComposeContentTestRule.setContent(kotlin.jvm.functions.Function0)'
at com.eygraber.portal.samples.simpleportal.android.SimplePortalAndroidTest.testSimplePortal(SimplePortalAndroidTest.kt:37)
and
java.lang.NoSuchMethodError: No static method setContent$default(Landroidx/activity/ComponentActivity;Landroidx/compose/runtime/CompositionContext;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)V in class Landroidx/activity/compose/ComponentActivityKt; or its super classes (declaration of 'androidx.activity.compose.ComponentActivityKt' appears in /data/app/~~JkcMMs1UWX31KJhsLcudBQ==/com.eygraber.portal.samples.simpleportal.android-z4_bbd1cDnprR1hNF3BDyA==/base.apk)
at com.eygraber.portal.samples.simpleportal.android.SimplePortalActivity.onCreate(SimplePortalActivity.kt:12)
Notice how setContent expects a kotlin.jvm.functions.Function0 instead of a kotlin.jvm.functions.Function2, which means that the Compose compiler isn't transforming the library functions. Rolling back to CMP 1.6.2 works, and using the Jetpack Compiler works as well.
Versions
- Libraries:
- Compose Multiplatform version: 1.6.10
- Kotlin version: 1.9.24
- JDK (for desktop issues): 21 and 17
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/eygraber/portal/tree/renovate/composejetbrains
- Run
./gradlew :samples:simple-portal:android-app:testReleaseUnitTest - See error
Did you apply the Kotlin compose compiler plugin?
Yes, the project works fine with CMP 1.6.2. The only change was bumping the version to 1.6.10. I've seen it in a few projects now.
Oh do you mean the new one from 2.0? This project is on 1.9.24.
I tried on my k2 branch and now it does work. The 1.6.10 changelog mentions that the Kotlin compose compiler plugin is needed for Kotlin 2.0-RC2, but this project is on 1.9.24
Identified a change causing this behaviour: https://github.com/JetBrains/compose-multiplatform/pull/4604/files#diff-b723358a9cc467fc156c914c8767b75387ca863c0387a2e0850a44e4d1086f18R29
Workaround:
- apply
kotlin("multiplatform")instead ofkotlin("android"), - rename the source set folder ("main" -> "androidMain")
- and configure the target:
kotlin {
androidTarget()
}
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.