Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Android Composables not transformed by compiler in 1.6.10 #4831

Closed
eygraber opened this issue May 17, 2024 · 6 comments · Fixed by #4879
Closed

Android Composables not transformed by compiler in 1.6.10 #4831

eygraber opened this issue May 17, 2024 · 6 comments · Fixed by #4879
Assignees
Labels
bug Something isn't working gradle Gradle plugin problems p:high High priority regression reproduced

Comments

@eygraber
Copy link
Contributor

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 eygraber added bug Something isn't working submitted labels May 17, 2024
@hfhbd
Copy link
Contributor

hfhbd commented May 18, 2024

Did you apply the Kotlin compose compiler plugin?

@eygraber
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@eygraber
Copy link
Contributor Author

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

@eymar
Copy link
Collaborator

eymar commented May 21, 2024

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 eymar added gradle Gradle plugin problems regression labels May 21, 2024
@igordmn igordmn added the p:high High priority label May 21, 2024
terrakok added a commit that referenced this issue May 28, 2024
…ugins are applied. (#4879)

Fix Compose Compiler configuration for Kotlin < 2.0 when kotlin-android
or kotlin-js gradle plugins are applied.

Fixes #4831

## Release Notes
### Fixes - Gradle Plugin
- Fix Compose Compiler configuration for Kotlin < 2.0 when
kotlin-android or kotlin-js gradle plugins are applied.
terrakok added a commit that referenced this issue May 28, 2024
…ugins are applied. (#4879)

Fix Compose Compiler configuration for Kotlin < 2.0 when kotlin-android
or kotlin-js gradle plugins are applied.

Fixes #4831

## Release Notes
### Fixes - Gradle Plugin
- Fix Compose Compiler configuration for Kotlin < 2.0 when
kotlin-android or kotlin-js gradle plugins are applied.

(cherry picked from commit c4e3640)
hoc081098 added a commit to hoc081098/kmp-viewmodel that referenced this issue May 30, 2024
* fix android

* import kotlin.reflect.KClass

* fixed following JetBrains/compose-multiplatform#4831 (comment)
JetBrains/compose-multiplatform#4831

* isStatic = true

* macos-13

* Update standalone-sample.yml
@okushnikov
Copy link
Collaborator

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working gradle Gradle plugin problems p:high High priority regression reproduced
Projects
None yet
6 participants