繁体   English   中英

为什么升级到jetpack compose 1.0.0-beta01后没有隐式导入kotlin.collections?

[英]Why kotlin.collections is not implicitly imported after upgrading to jetpack compose 1.0.0-beta01?

升级到jetpack compose 1.0.0-beta01后,我尝试使用arrayListOf,listOf from kotlin.collections,但它们似乎没有隐式导入。

您的问题可能与您使用的Kotlin 版本有关。

我想我在更新到新版本的 Jetpack Compose 库时经历了与您类似的过程,作为“副作用”,我被迫更新 kotlin 和 kotlin-gradle-plugin 版本然后间接导致您的(和我的)问题。 以下解决方法应该可以解决它。

将 Jetpack Compose 更新为1.0.0-beta01后,您很可能正在使用Kotlin 1.4.30 将 Kotlin 更新到已修复的1.4.31版本,您的问题将几乎“解决”。

如果您更感兴趣,我认为整个问题与 1.4.30 中的以下错误有关https://youtrack.jetbrains.com/issue/KT-44845

现在,在尝试构建您的项目后,您将收到一个很好的错误This version (1.0.0-alpha13) of the Compose Compiler requires Kotlin version 1.4.30 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you.). This version (1.0.0-alpha13) of the Compose Compiler requires Kotlin version 1.4.30 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you.).

suppressKotlinVersionCompatibilityCheck是一个编译参数,在我的情况下,我在 android -> kotlinOptions 下的模块 build.gradle 文件中设置了这种参数:

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8
    useIR = true
        
    //here -->
    freeCompilerArgs += ["-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"]
} 

它还取决于 build.gradle 文件的类型。 Read more about how to set those compile arguments at Configure compiler arguments where are described different ways for groovy and also for kotlin based gradle files.

现在您应该没问题,但请记住,一旦有新版本的 Jetpack Compose 依赖于较新版本的 Kotlin,您就想摆脱suppressKotlinVersionCompatibilityCheck参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM