Has anyone encountered this issue? I'm trying to d...
# compose
a
Has anyone encountered this issue? I'm trying to do `
Copy code
composeView.setContent {
    Text(text = "WELCOME TO COMPOSE!")
}
and I get a runtime error
java.lang.NoSuchMethodError: No virtual method setContent(Lkotlin/jvm/functions/Function0;)V in class Landroidx/compose/ui/platform/ComposeView; or its super classes (declaration of 'androidx.compose.ui.platform.ComposeView' appears in /data/app/taxi.tap30.passenger.debug--kKKwSbfzrf377VbKRnzSQ==/base.apk)
c
Are you using
buildSrc
?
t
@Adib Faramarzi Did you try this?
👍 1
l
The setContent() extension is in the `
Copy code
androidx.core:core-ktx
So check if you have that has a dependency
c
If you use buildSrc, you can check the solution for this here: https://issuetracker.google.com/issues/176079157
a
@Colton Idle No, regular groovy.
@theapache64 @Luis Thanks, let me check
The core-ktx did not solve the issue. What's weird is the library is definitely in the module since the IDE can recognize the code (and ComposeView)
l
Ah sorry, I missread the error message. setContent is an extension on Activity, not View
a
It's a ComposeView.
l
Yes, I meant I was reading the error like it was a problem with an activity
I think maybe a rebuild project is in order
a
Sure
e
to me it looks like compose plugin isn't working, but I don't have a guess as to why
a
Yes this looks like compose compiler plugin not being correctly applied as
@Composable () -> Unit
should be
Function2
instead of
Function0
after transformation performed by the compiler plugin. Are you enabling compose compiler plugin by specifying
buildFeatures.compose = true
in your build script?
c
Never forget to check the imports because they will have similar the EXACT names of the wrong ones 🙂 ❤️ Hell ❤️
b
buildFeatures { compose true }
a
The buildFeatures is included. Re-building also didn't help.
b
Is this activity/fragment in a module or :app
a
in a module
could this be related to the fact that I have disabled the new JVM IR backend? (
useOldBackend true
)
👌 1
b
Did you define buildFeatures in the module too?
a
Yes
b
Compose also needs import in the main app module
👀 1
a
I have the dependencies only in the module though
b
Or api() the compose deps in the module
a
Let me see
b
Using dagger as well?
a
Yes
Including the script in the main app module did not help
a
could this be related to the fact that I have disabled the new JVM IR backend? (useOldBackend true )
The compose compiler plugin is an IR plugin so yes, you've ensured it's not running on your code by doing this 🙂
🙌 1
a
@Adam Powell That is unfortunate... I don't seem to be able to bring compose to our project any time soon, due to the fact that Kotlin 1.5.10 (until 1.5.30) has a major issue with kotlin.Result types (and
runCatching
) and compose relies on these Kotlin versions
I'm wondering If I can turn the old backend off for all other modules and turn it on for the compose module.
a
That should work fine. It's how a lot of projects worked with compose before 1.5 where the IR backend became the default
a
Thanks, that would be okay. I'll check.
I managed to make it work. Right now, all modules rely on the old backend and there's a new compose module with
useOldBackend=true
and everything seems to run smoothly.
n
This error encountered to me now, I can't solve by adding
useOldBackend=true
417 Views