如何使用 Kotlin 1.6.20 编译 compose 1.1.1

Cya*_*yao 8 kotlin android-jetpack-compose

我在构建项目时遇到这样的错误:

e: This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.6.20 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).

我正在使用最新的 IntelliJ Pro 和最新的 Kotlin 版本。

我怎样才能编译项目?

Fel*_*uki 13

对于 kotlin 版本 1.6.20,您需要在 build.gradle 中添加此行

 composeOptions {
    kotlinCompilerExtensionVersion '1.2.0-alpha08'
}
Run Code Online (Sandbox Code Playgroud)

请参阅 google 的此文档,了解有关 kotlin 对不同 compose 版本的兼容性的更多信息


小智 6

您需要使用 kotlin 版本 1.6.10 来使用此版本的 compose 编译项目。在下一个版本中可能会添加新版本的 kotlin 支持。更改 gradle/maven 属性来解决此问题。

在 Gradle 中更改:

kotlin("jvm") version "1.6.20"
Run Code Online (Sandbox Code Playgroud)

到:

kotlin("jvm") version "1.6.10"
Run Code Online (Sandbox Code Playgroud)

或者你可以添加编译器参数(但可能会有问题):

"-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
Run Code Online (Sandbox Code Playgroud)