Compose 1.1.1 kotlin 编译器问题

Compose 1.1.1 kotlin compiler issue

我的项目有问题。

这是一个全新的干净的 compose 项目,我正在使用

Android 大黄蜂工作室 | 2021.1.1 补丁 3 Build #AI-211.7628.21.2111.8309675,建于 2022 年 3 月 16 日

更新信息:我安装了最新版本的 kotlin (1.6.20)(根据 android 工作室),但我的 kotlin 中有很多版本缓存文件夹,正常吗?

我唯一做的就是按照 android 工作室的建议将撰写版本设置为 1.1.1

buildscript {
    ext {
        compose_version = '1.1.1'
    }
}

并为 androidx.compose.material3

添加了另一个依赖项
dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation "androidx.compose.animation:animation:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
    implementation 'androidx.activity:activity-compose:1.4.0'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

    //Material 3 compose
    implementation "androidx.compose.material3:material3:1.0.0-alpha09"

    def room_version = "2.4.2"

    implementation "androidx.room:room-common:$room_version"
    implementation "androidx.room:room-runtime:$room_version"
    annotationProcessor "androidx.room:room-compiler:$room_version"

}

我遇到了这个错误:

Task :app:compileDebugKotlin
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.5.21 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.30/5fd47535cc85f9e24996f939c2de6583991481b0/kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.5.30/525f5a7fa6d7790a571c07dd24214ed2dda352fe/kotlin-stdlib-jdk7-1.5.30.jar (version 1.5)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.6.10/b8af3fe6f1ca88526914929add63cf5e7c5049af/kotlin-stdlib-1.6.10.jar (version 1.6)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.6.10/c118700e3a33c8a0d9adc920e9dec0831171925/kotlin-stdlib-common-1.6.10.jar (version 1.6)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.30/5fd47535cc85f9e24996f939c2de6583991481b0/kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.5.30/525f5a7fa6d7790a571c07dd24214ed2dda352fe/kotlin-stdlib-jdk7-1.5.30.jar (version 1.5)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.6.10/b8af3fe6f1ca88526914929add63cf5e7c5049af/kotlin-stdlib-1.6.10.jar (version 1.6)
    C:/Users/Ulkan/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.6.10/c118700e3a33c8a0d9adc920e9dec0831171925/kotlin-stdlib-common-1.6.10.jar (version 1.6)


> Task :app:compileDebugKotlin FAILED

按照错误消息的建议将 Kotlin 版本从 1.5.21 升级到 1.6.10

请检查下面提到的 link 这有助于确定您使用的 compose 版本与哪个 kotlin 版本兼容。

https://developer.android.com/jetpack/androidx/releases/compose-kotlin

更多内容,

  1. 如果您使用的是 kotlin 合成导入,则必须通过使用视图绑定或简单地通过调用 findViewById 来替换所有这些。
  2. kotlin-android-extensions 已弃用,因此请将其替换为 kotlin-parcelize
  3. 如果有用于模型类的@Parcelize注解,那么你必须将它的导入从kotlinx.android.parcel.Parcelize替换为导入kotlinx.parcelize.Parcelize