我正在将Jetpack Compose集成到我的应用程序的legacy模块中,并在构建时运行到一个问题IncompatibleComposeRuntimeVersionException中。我希望能帮你解决这个问题。
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.1) expects a minimum runtime version of 1.0.1.
at androidx.compose.compiler.plugins.kotlin.VersionChecker.outdatedRuntimeWithUnknownVersionNumber(VersionChecker.kt:116)
at androidx.compose.compiler.plugins.kotlin.VersionChecker.check(VersionChecker.kt:81)
at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:57)
...我一直在关注official guide,并在the other relevant stackoverflow post上寻找答案。我的应用程序的代码与官方指南非常匹配,相关的SO帖子也没有帮助。
以下是依赖项
compose_activity: "androidx.activity:activity-compose:1.3.1",
compose: [ // versions.androidx.compose = 1.0.1
"androidx.compose.ui:ui:${versions.androidx.compose}",
"androidx.compose.ui:ui-tooling:${versions.androidx.compose}",
"androidx.compose.material:material:${versions.androidx.compose}",
"androidx.compose.foundation:foundation:${versions.androidx.compose}",
"androidx.compose.runtime:runtime:${versions.androidx.compose}",
"androidx.compose.runtime:runtime-livedata:${versions.androidx.compose}",
"androidx.compose.runtime:runtime-rxjava2:${versions.androidx.compose}",
],在项目build.gradle中
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.1'
}
kotlinOptions {
jvmTarget = '1.8'
}
}在应用程序、传统和项目build.gradle中
buildFeatures {
// Enables Jetpack Compose for this module
compose true
}在通用ui模块中(在应用程序和遗留模块中实现)
api libs.androidx.compose
api libs.androidx.compose_activity发布于 2021-09-09 16:16:22
解决方案是将composeOptions、buildFeatures、compileOptions中的组合设置代码移动到编写组合代码的legacy模块。官方文档指定了app模块,这并不总是准确的。
发布于 2021-09-08 21:19:44
尝试将此代码添加到项目级构建中
buildscript {
ext {
compose_version = '1.0.1' //latest is 1.0.2 though (stable)
}
}https://stackoverflow.com/questions/69109394
复制相似问题