freeletics / FlowRedux

Kotlin Multiplatform Statemachine library with nice DSL based on Flow from Kotlin Coroutine's.
https://freeletics.github.io/FlowRedux/
Apache License 2.0
711 stars 27 forks source link

Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option #725

Closed ChaabouniMed closed 3 months ago

ChaabouniMed commented 3 months ago

I migrated from version 1.2.0 to 1.2.2 and encountered the following error:

"Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify the proper '-jvm-target' option."

Did the jvmTarget change in this version?

I have changed jvmTarget in my build.gradle file like this :

compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = "11" }

but I got this error now : "Execution failed for task ':arc-si-types:compileDebugKotlinAndroid'.

Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlinAndroid' (11)."

gabrielittner commented 3 months ago

Yes it changed when we updated the JDK that we're building with because JDK22 deprecated support for targeting Java 8, I forgot to mention it in the release notes.

This should work

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = "11"
    }
}

Which Android Gradle Plugin version are you using?

ChaabouniMed commented 3 months ago

I'm using: agp = "8.2.0"

gabrielittner commented 3 months ago

Could you try adding this to your project? kts

tasks.withType<JavaCompile>().configureEach {
    this.sourceCompatibility = "11"
    this.targetCompatibility = "11"
}

groovy

tasks.withType(JavaCompile).configureEach {
    sourceCompatibility = "11"
    targetCompatibility = "11"
}
ChaabouniMed commented 3 months ago

I have aaded this to all my project modules and the error is still there.

NB: kotlinOptions is depracated, and this warning is displayed : 'kotlinOptions(KotlinJvmOptionsDeprecated / = KotlinJvmOptions /.() -> Unit): Unit' is deprecated. Please migrate to the compilerOptions DSL. More details are here: https://kotl.in/u1r8ln

The warning is displayed in this scope of my kts :

tasks.withType { kotlinOptions { freeCompilerArgs += listOf( "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-Xexpect-actual-classes" ) } }

and it wasn't when my jvmTarget was at 1.8

gabrielittner commented 3 months ago

It's hard to say but if that also doesn't work it seems like something else is setting it to 1.8 again. What Kotlin does is that it compares the target on the java task with the jvmTarget on the Kotlin task. From the error in your initial post jvmTarget gets applied but something sets targetCompatibility to 1.8.

The kotlinOptions block was deprecated in Kotlin 2.0 in favor of compilerOptions, but that has nothing to do with the target.

ChaabouniMed commented 3 months ago

It's ok I didn't add the sourceCompatibility and the targetCompatibility in a specefic component in my project. Thanks