在现有项目中集成 Jetpack Compose

3

我正在尝试将Compose添加到我的项目中,但遇到了以下问题:

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)....
我有以下配置:
  • 目标和编译sdk设置为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"
也许您可以提供一些建议。

我也遇到了同样的问题,但仍然找不到解决方法 :/ - datienza
1个回答

0
请确保在build.gradle文件的android代码块中添加以下行:
android {
 ... 

    buildFeatures {
       compose true
    }
    composeOptions {
       kotlinCompilerExtensionVersion '1.0.4'//change this value
       kotlinCompilerVersion '1.5.31' // change this value
    }
}
  1. 确保您在类的init块中没有可组合值初始化

  2. 如果什么都不起作用,请删除.gradle .idea并使缓存失效,然后重新启动


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接