Ale*_*scu 12 android-jetpack-compose
我正在尝试使用1.4.21-2kotlin 的最新版本,该版本有一个修复程序,允许您使用 Compose + Kotlin 序列化而不会挂起构建。这一切都很好,但是,Compose 编译器不知道它并给出以下(相当无用的)错误:
e:Compose Compiler 的此版本 (1.0.0-alpha09) 需要 Kotlin 1.4.21 版,但您似乎使用的是 Kotlin 1.4.21-2 版,该版本不兼容。请修复您的配置(或者
suppressKotlinVersionCompatibilityCheck但不要说我没有警告您!)。
我很想提供那个抑制标志,但是我不知道把它放在哪里......我花了大约一个小时试图将它放在我的 gradle 文件中的随机位置,例如 in composeOptions,但没有运气。我也尝试了我知道的所有 google-fu,但似乎没有人真正使用过它并写过任何关于它的东西。
任何想法如何摆脱这种困境?
小智 16
我对消息有同样的问题:
e: This version (1.0.0-alpha11) of the Compose Compiler requires Kotlin version 1.4.21-2 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
Run Code Online (Sandbox Code Playgroud)
添加编译器参数解决了我的问题:
"-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
Run Code Online (Sandbox Code Playgroud)
您可以将其添加到所有KotlinCompile任务中。在应用程序级别的 Gradle 中,它如下所示:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += [
"-Xallow-jvm-ir-dependencies",
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
]
}
}
Run Code Online (Sandbox Code Playgroud)
Hum*_*Bee 13
对于多模块项目,将抑制标志添加到项目的根级别build.gradle内部allprojects {}部分:
allprojects {
repositories {
google()
mavenCentral()
}
// Suppress Compose Kotlin compiler compatibility warning
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += [
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 KTS,
android {
...
kotlinOptions {
jvmTarget = "1.8"
useIR = true
freeCompilerArgs = listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
)
...
}
Run Code Online (Sandbox Code Playgroud)
更好的解决方案是在模块文件中添加一个composeOptions部分。:appbuild.gradle
composeOptions {
kotlinCompilerExtensionVersion = "1.3.2"
}
Run Code Online (Sandbox Code Playgroud)
这是Android Compose Kotlin 文档中推荐的内容
它是一个命令行参数。
-P plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4303 次 |
| 最近记录: |