I'm getting a java.lang.NoSuchMethodError
exception when trying to run setContent{ Composable() }
.
Full code:
class ComposeFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
ComposeView(requireContext()).apply { setContent { Text("hello") } }
}
Full exception:
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/~~3OmVKUoYitZ_S4H81xmyuw==/my.app.package-PAQxAKmtRuhnzp4M2DME8w==/base.apk)
Solutions/answers to similar questions suggest adding buildFeatures { compose = true }
or kotlinCompilerExtensionVersion
, I have already done this but the issue persists.
My full compose Gradle config is as follows:
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
useIR = true
}
buildFeatures {
compose = true
}
composeOptions{
kotlinCompilerExtensionVersion = "1.0.5"
}
implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.compose.material:material:1.0.5" )
implementation( "androidx.compose.animation:animation:1.0.5" )
implementation( "androidx.compose.ui:ui-tooling:1.0.5" )
implementation( "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07" )
androidTestImplementation( "androidx.compose.ui:ui-test-junit4:1.0.5" )