Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I put the `suppressKotlinVersionCompatibilityCheck` flag?

I'm trying to use the 1.4.21-2 version of kotlin which is a recent version that has a fix that allows you to use Compose + Kotlin serialization without the build hanging. This is all great, however, the Compose compiler does not know about it and gives the following (rather unhelpful) error:

e: This version (1.0.0-alpha09) of the Compose Compiler requires Kotlin version 1.4.21 but you appear to be using Kotlin version 1.4.21-2 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).

I would love to provide that suppression flag, however I don't know where to put it... I've spent about an hour trying to put it in random places in my gradle files, for example in composeOptions, but no luck. I also tried all the google-fu I know, but nobody seems to have actually used this and wrote anything about it.

Any ideas how to get out of that predicament?

like image 649
Alexandru Cristescu Avatar asked Jan 02 '21 23:01

Alexandru Cristescu


Video Answer


3 Answers

I have the same problem with message:

e: This version (1.0.0-alpha11) of the Compose Compiler requires Kotlin version 1.4.21-2 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

Adding compiler args solved my problem:

"-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"

You can add it to all KotlinCompile tasks. In app level Gradle it looks like the following:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += [
                "-Xallow-jvm-ir-dependencies",
                "-P",
                "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
        ]
    }
}
like image 112
karenkov_id Avatar answered Oct 27 '22 19:10

karenkov_id


if you are using KTS,

android {
    ...

    kotlinOptions {
        jvmTarget = "1.8"
        useIR = true

        freeCompilerArgs += listOf(
            "-P",
            "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
        )

    ...
}
like image 39
sonique Avatar answered Oct 27 '22 17:10

sonique


For multi-module projects add the suppression flag to project's root-level build.gradle inside allprojects {} section:

allprojects {
    repositories {
        google()
        mavenCentral()
    }

    // Suppress Compose Kotlin compiler compatibility warning
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            freeCompilerArgs += [
                    "-P",
                    "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
            ]
        }
    }
}
like image 12
HumbleBee Avatar answered Oct 27 '22 19:10

HumbleBee