'Integrate Jetpack Compose in existing project

I'm trying to add compose to my project and encountered this issue:

org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /Users/admin/app/src/main/java/ro/.../DeviceInputFragment.kt
The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.backend.common.ir.IrUtilsKt.copyValueParametersToStatic(IrUtils.kt:264)....

I have the following configuration:

  • Target and compile sdk set to 32

  • composeOptions { kotlinCompilerExtensionVersion "1.1.1" }

  • kotlinVersion = '1.6.10'

  • classpath 'com.android.tools.build:gradle:7.0.4'

  • kotlinOptions { jvmTarget = "1.8" useIR = true }

  • buildFeatures { compose = true }

composeVersion = "1.1.1"

    implementation "androidx.compose.runtime:runtime:$composeVersion"
    implementation "androidx.compose.ui:ui:$composeVersion"
    implementation "androidx.compose.foundation:foundation:$composeVersion"
    implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
    implementation "androidx.compose.material:material:$composeVersion"
    implementation "androidx.compose.runtime:runtime-livedata:$composeVersion"
    implementation "androidx.compose.ui:ui-tooling:$composeVersion"

Maybe you can provide some suggestions.



Solution 1:[1]

  1. Make sure you add these lines in your android block in build.gradle
android {
 ... 

    buildFeatures {
       compose true
    }
    composeOptions {
       kotlinCompilerExtensionVersion '1.0.4'//change this value
       kotlinCompilerVersion '1.5.31' // change this value
    }
}
  1. Make sure you do not have composable value initialization in the init block of a class

  2. if nothing works. Delete .gradle .idea and Invalidate Caches and restart

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Narendra_Nath