Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

After upgrading to jetpack compose 1.0.0-beta01, I tried to use arrayListOf, listOf from kotlin.collections but they seemed to not implicitly imported.

like image 523
Ihoby Christian Rakotoarivony Avatar asked Mar 02 '23 17:03

Ihoby Christian Rakotoarivony


1 Answers

Your problem is probably related to what Kotlin version you are using.

I guess I went through a similar process as you did when I was updating to the new version of Jetpack Compose library, where as a "side effect" I was forced to update kotlin and kotlin-gradle-plugin version what then indirectly caused your (and mine) problem. Following workaround should fix it.

Most likely you are using Kotlin 1.4.30 after updating Jetpack Compose to 1.0.0-beta01. Update Kotlin to fixed 1.4.31 version and your problem will be ALMOST "resolved".

I think the whole problem is somehow related to the following bug in 1.4.30 if you are more interested https://youtrack.jetbrains.com/issue/KT-44845

Now after trying to build your project you will get a nice error saying 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 is a compile argument which in my case I have set in module build.gradle file under android -> kotlinOptions this way:

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

It also depends on the type of build.gradle files. 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.

Now you should be fine but bear in mind that you want to get rid of the suppressKotlinVersionCompatibilityCheck argument as soon as there is a new version of Jetpack Compose relying on a newer version of Kotlin.

like image 163
David Kneys Avatar answered Apr 26 '23 23:04

David Kneys