When trying jetpack compose it show error: compiler backend and cannot be loaded by the old compiler When trying jetpack compose it show error: compiler backend and cannot be loaded by the old compiler android android

When trying jetpack compose it show error: compiler backend and cannot be loaded by the old compiler


Please add this task in your app/build.gradle file:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {    kotlinOptions {        jvmTarget = "1.8"        freeCompilerArgs += ["-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check"]    }}


The default app/build.grade, when creating a new project with an "Empty Compose Activity", includes the following options.

android {    // other options    kotlinOptions {        jvmTarget = '1.8'        useIR = true    }    // more options}

Adding these options (specifically useIR = true) seemed to fix the error for me.


The useIR option references a new JVM backend for Kotlin for which the documentation specifically states the following.

If you enable Jetpack Compose, you will automatically be opted in to the new JVM backend without needing to specify the compiler option in kotlinOptions.

Which is seemingly incorrect.


Following the steps in the official setup guide lead me to the same problem.

Adding the necessary dependencies/configuration for the compose library fixed this issue for me.