compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Android Composables not transformed by compiler in 1.6.10

Open eygraber opened this issue 1 year ago • 5 comments

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:

  1. Clone https://github.com/eygraber/portal/tree/renovate/composejetbrains
  2. Run ./gradlew :samples:simple-portal:android-app:testReleaseUnitTest
  3. See error

eygraber avatar May 17 '24 22:05 eygraber

Did you apply the Kotlin compose compiler plugin?

hfhbd avatar May 18 '24 12:05 hfhbd

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.

eygraber avatar May 19 '24 01:05 eygraber

Oh do you mean the new one from 2.0? This project is on 1.9.24.

eygraber avatar May 19 '24 01:05 eygraber

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

eygraber avatar May 19 '24 04:05 eygraber

Identified a change causing this behaviour: https://github.com/JetBrains/compose-multiplatform/pull/4604/files#diff-b723358a9cc467fc156c914c8767b75387ca863c0387a2e0850a44e4d1086f18R29

Workaround:

  • apply kotlin("multiplatform") instead of kotlin("android"),
  • rename the source set folder ("main" -> "androidMain")
  • and configure the target:
kotlin {
    androidTarget()
}

eymar avatar May 21 '24 09:05 eymar

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

okushnikov avatar Jul 14 '24 14:07 okushnikov