Facing Kotlin compiler backend compatibility issue while using Jetpack Compose with ComposeView class

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?

Your problem is that Compose version 0.1.0-dev17 is outdated. It originates from the early development phase and is not compatible with modern Kotlin compilers. I encountered this exact issue with older Compose versions in production — the compiler backend won’t align properly as these versions were built against significantly different Kotlin compiler versions.

It’s advisable to update to at least Compose 1.0.0 or preferably the latest stable release. Ensure your Kotlin version aligns with the official Compose compiler compatibility map. Also, replace the deprecated androidx.ui:ui-tooling dependency with androidx.compose.ui:ui-tooling. After making these updates, perform a comprehensive clean and rebuild to eliminate any cached compilation issues.

Woah, 0.1.0-dev17? That’s a throwback! Are you stuck on that version because of legacy project requirements? What Kotlin version are you using? Backend mismatches are tough to debug without the full setup details.

same thing happened to me. those compose versions are ancient - you’re running dev builds from 2020. just bump everything to the latest stable release. the compose bom handles version management now, so it’s way easier. also do a complete clean of your build folder - gradle caches can mess things up.