I am encountering an error when I work with Jetpack Compose. The message indicates that Class 'androidx.compose.ui.platform.ComposeView' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler
. This issue occurs in my fragment when utilizing ComposeView.
Here’s the code for my fragment:
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_delivered, container, false).apply {
findViewById<ComposeView>(R.id.compose_view).setContent {
MaterialTheme {
Surface {
Text("Hello")
}
}
}
}
}
Here are the versions I am currently using:
accompanistVersion = "0.1.9"
composeVersion = '0.1.0-dev17'
In my build.gradle file:
buildFeatures {
compose true
dataBinding true
}
composeOptions {
kotlinCompilerVersion rootProject.kotlinVersion
kotlinCompilerExtensionVersion rootProject.composeVersion
}
// Dependencies
implementation "androidx.compose.runtime:runtime:$rootProject.composeVersion"
implementation "androidx.compose.ui:ui:$rootProject.composeVersion"
implementation "androidx.compose.foundation:foundation:$rootProject.composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$rootProject.composeVersion"
implementation "androidx.compose.material:material:$rootProject.composeVersion"
implementation "androidx.compose.ui:ui-viewbinding:$rootProject.composeVersion"
implementation "androidx.ui:ui-tooling:$rootProject.composeVersion"
implementation "androidx.compose.runtime:runtime-livedata:$rootProject.composeVersion"
implementation "com.google.android.material:compose-theme-adapter:$rootProject.composeVersion"
implementation "dev.chrisbanes.accompanist:accompanist-coil:$rootProject.accompanistVersion"
Does anyone have suggestions on how to resolve this compatibility issue?