Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

android - Jetpack Compose on Kotlin 1.5.0

I've updated to Kotlin 1.5 last week, and after yesterday having seen the intention of Google to make Jetpack Compose the preferred option for designing UIs, I wanted to do some testing.

The issue is that having my project updated to Kotlin 1.5, when trying to build the project I get the following error:

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

Is Kotlin 1.5 incompatible with Jetpack Compose? After googling the issue I found the 1.5.0-M2 release, which mentions Jetpack Compose, but not in an "incompatible" manner.

Do you have any answer to this? Should I use suppressKotlinVersionCompatibilityCheck? In that case, may I add it directly to android.kotlinOptions in the module's build.gradle file?

Thanks in advance.

Edit 1: I've found that I should add suppressKotlinVersionCompatibilityCheck as a builder arg:

android {
    ...
    kotlinOptions {
        ...
        freeCompilerArgs += [
            "-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
        ]
        ...
    }
    ...
}

But it's still not compiling, I get this error from the compiler:

java.lang.NoClassDefFoundError: org/jetbrains/kotlin/ir/descriptors/WrappedSimpleFunctionDescriptor
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.buildFunction(LiveLiteralTransformer.kt:842)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.irLiveLiteralGetter(LiveLiteralTransformer.kt:933)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitConst(LiveLiteralTransformer.kt:426)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitConst(IrElementTransformerVoid.kt:138)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitConst(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl.accept(IrConstImpl.kt:33)
    at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:33)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1$3.invoke(LiveLiteralTransformer.kt:624)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1$3.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$enter(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1.invoke(LiveLiteralTransformer.kt:623)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitCall(LiveLiteralTransformer.kt:612)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:199)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl.accept(IrCallImpl.kt:47)
    at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:33)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1$3.invoke(LiveLiteralTransformer.kt:624)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1$3.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$enter(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1.invoke(LiveLiteralTransformer.kt:623)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitCall$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitCall(LiveLiteralTransformer.kt:612)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:199)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl.accept(IrCallImpl.kt:47)
    at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:33)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitBranch$1.invoke(LiveLiteralTransformer.kt:738)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitBranch$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitBranch(LiveLiteralTransformer.kt:737)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBranch(IrElementTransformerVoid.kt:255)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBranch(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.impl.IrBranchImpl.transform(IrWhenImpl.kt:56)
    at org.jetbrains.kotlin.ir.expressions.IrWhen.transformChildren(IrWhen.kt:37)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitExpression(IrElementTransformerVoid.kt:131)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitWhen(IrElementTransformerVoid.kt:247)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$visitWhen$s1031542550(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitWhen$1.invoke(LiveLiteralTransformer.kt:705)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitWhen$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:117)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor$siblings$1.invoke(DurableKeyVisitor.kt:131)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:131)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.siblings(LiveLiteralTransformer.kt:192)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitWhen(LiveLiteralTransformer.kt:704)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitWhen(IrElementTransformerVoid.kt:248)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitWhen(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.IrWhen.accept(IrWhen.kt:29)
    at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:33)
    at org.jetbrains.kotlin.ir.expressions.IrExpression.transform(IrExpression.kt:26)
    at org.jetbrains.kotlin.ir.expressions.IrBlockBody.transformChildren(IrBody.kt:62)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBody(IrElementTransformerVoid.kt:108)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBlockBody(IrElementTransformerVoid.kt:117)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$visitBlockBody$s1031542550(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitBlockBody$1.invoke(LiveLiteralTransformer.kt:795)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitBlockBody$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.siblings(DurableKeyVisitor.kt:117)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.siblings(LiveLiteralTransformer.kt:193)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitBlockBody(LiveLiteralTransformer.kt:794)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBlockBody(IrElementTransformerVoid.kt:118)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBlockBody(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.expressions.IrBlockBody.accept(IrBody.kt:54)
    at org.jetbrains.kotlin.ir.expressions.IrBody.transform(IrBody.kt:27)
    at org.jetbrains.kotlin.ir.declarations.IrFunction.transformChildren(IrFunction.kt:69)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElementTransformerVoid.kt:57)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFunction(IrElementTransformerVoid.kt:69)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:72)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.access$visitSimpleFunction$s1031542550(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitSimpleFunction$1.invoke(LiveLiteralTransformer.kt:654)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer$visitSimpleFunction$1.invoke(LiveLiteralTransformer.kt:158)
    at androidx.compose.compiler.plugins.kotlin.lower.DurableKeyVisitor.enter(DurableKeyVisitor.kt:96)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.enter(LiveLiteralTransformer.kt:191)
    at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitSimpleFunction(LiveLiteralTransformer.kt:654)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:73)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:24)
    at org.jetbrains.kotlin.ir.declarations.IrSimpleFunction.accept(IrSimpleFunction.kt:29)
    at org.jetbrains.kotlin.ir.IrElement$DefaultImpls.transform(IrElement.kt:32)
    at org.jetbrains.kotlin.ir.IrElementBase.transform(IrElementBase.kt:19)
    at org.jetbrains.kotlin.ir.util.TransformKt.transformInPlace(transform.kt:35)
    at org.jetbrains.kotlin.ir.declarations.IrClass.transformChildren(IrClass.kt:67)
    at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElem

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Update: androidx.compose.compiler:compiler:1.0.0-beta08 is released (June 2, 2021).

From this version, the expected version of Kotlin is 1.5.10.

dependencies {
    implementation "androidx.compose.compiler:compiler:1.0.0-beta08"
}

android {
    buildFeatures {
        compose true
    }

    composeOptions {
        kotlinCompilerVersion "1.5.10"
        kotlinCompilerExtensionVersion "1.0.0-beta08"
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

See more:


Compose compiler 1.0.0-beta07 is not supporting Kotlin 1.5.0 yet.

And I found that the changes of supporting Kotlin 1.5.0 have merged, but not released yet.

https://android-review.googlesource.com/c/platform/frameworks/support/+/1651538

For this moment, in my opinion, you should use 1.4.3 and wait for the next version (1.0.0:beta08 or 1.0.0)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...