Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

后端 未结 30 1030
走了就别回头了
走了就别回头了 2020-11-29 14:36

When trying to run the Example CorDapp (GitHub CorDapp) via IntelliJ, I receive the following error:

Cannot inline bytecode built with JVM target 1.8 int

相关标签:
30条回答
  • 2020-11-29 15:19

    In Android Studio 4.3.2 adding through the below procedure is not working.

    1. Open the IntelliJ preferences
    2. Go to Build, Execution, Deployment > Compiler > Kotlin Compiler BUT Other Settings > Kotlin compiler if Android Studio > 3.4
    3. Change the Target JVM version to 1.8
    4. Click Apply

    The reason is, Android studio is unable to add the below code in the module level Gradle file. Please add it manually.

    kotlinOptions {
        jvmTarget = "1.8"
    }
    

    Just for the addon, search Target JVM version in the android studio search. It will take you directly to the option.

    0 讨论(0)
  • 2020-11-29 15:19

    in most cases this is enough:

    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    

    if you have declared custom Gradle tasks like integrationTest for example, add a configuration for compile<YourTaskName>Kotlin as well:

    compileIntegrationTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    
    0 讨论(0)
  • 2020-11-29 15:20

    For me the reason was this configuration in my build gradle was in some modules and in some it wasnt

    android {  
    ...      
    kotlinOptions {
            val options = this as KotlinJvmOptions
            options.jvmTarget = "1.8"
        }
    ...
    android {
    
    0 讨论(0)
  • 2020-11-29 15:21

    Setting sourceCompatibility = JavaVersion.VERSION_1_8 enables desugaring, but it is currently unable to desugar all the Java 8 features that the Kotlin compiler uses.

    Fix - Setting kotlinOptions.jvmTarget to JavaVersion.VERSION_1_8 in the app module Gradle would fix the issue.

    Use Java 8 language features: https://developer.android.com/studio/write/java8-support

    android {
      ...
      // Configure only for each module that uses Java 8
      // language features (either in its source code or
      // through dependencies).
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
      // For Kotlin projects
      kotlinOptions {
        jvmTarget = "1.8"
      }
    }
    
    0 讨论(0)
  • 2020-11-29 15:22

    Using the Kotlin Gradle DSL, this solved the issue for me. I added this to the build.gradle.kts. This is in addition to the answer by Joel

    val compileKotlin: KotlinCompile by tasks
    compileKotlin.kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
    
    0 讨论(0)
  • 2020-11-29 15:22

    I'm using Kotlin and Gradle for normal JVM development, (not android) and this worked for me in build.gradle:

    allprojects {
        tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
            kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
        }
    }
    
    0 讨论(0)
提交回复
热议问题