e:此版本 (1.3.2) 的 Compose 编译器需要 Kotlin 版本 1.7.20,但您似乎使用的是 Kotlin 版本 1.9.23,目前尚不清楚该版本是否兼容。
这个错误是不言自明的。对于其他匹配的项目,兼容性做得很好。由于某种原因,无论我在这个项目中做什么,错误仍然存在。没有提及 1.3.2 的 compose 编译器。只有主应用程序使用 compose。我尝试过清理/失效,结果相同。
这是一个多模块项目。 gradle 构建脚本都使用相同的 kotlin 版本。
build.gradle(项目)
buildscript {
ext {
kotlin_version = '1.9.23'
compose_version = '1.6.5'
kotlinCompilerExtensionVersion = '1.5.11'
...
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
}
}
build.gradle(应用程序)
apply plugin: 'kotlin-android'
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
composeOptions {
kotlinCompilerExtensionVersion kotlinCompilerExtensionVersion
}
buildFeatures {
compose true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
// Compose
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// somewhere on a google doc it noted to NOT include this. Here just in case.
// implementation "androidx.compose.material:material:$compose_version"
}
build.gradle(模块a)
plugins {
id 'com.android.library'
}
apply plugin: 'kotlin-android'
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
}
build.gradle(模块b)
plugins {
id 'com.android.library'
}
apply plugin: 'kotlin-android'
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
这对我有用,尝试更换这条线
kotlinCompilerExtensionVersion kotlinCompilerExtensionVersion
与:
kotlinCompilerExtensionVersion rootProject.ext.kotlinCompilerExtensionVersion
当我用您的示例创建空项目时,
kotlinCompilerExtensionVersion
引用了ComposeOptions#kotlinCompilerExtensionVersion
,它可能具有默认值1.3.2
,因此它从自身到自身设置相同的值,而不是从ext
属性中获取值。