当试图通过IntelliJ运行示例CorDapp (GitHub CorDapp)时,我收到以下错误:

不能将使用JVM目标1.8构建的字节码内联为当前的字节码 使用JVM目标1.6构建

如何修改IntelliJ设置,使所有字节码都使用相同的JVM目标构建?


当前回答

正如在Kotlin网站的using-maven文档中所写的:

你只需要把<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>放到pom.xml的属性部分

其他回答

在我的例子中,我通过以下两个步骤解决了这个问题

1. Go to android studio preferences -> other settings -> kotlin compiler -> set Target JVM version = 1.8 
   if it doesn't work then go to the second option.

2. In your module-level build.gradle file add 
   compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }

对于最近版本的Android Studio,如果仅仅更改Kotlin Target VM版本不工作。

文件➞项目结构➞模块(app):将“源兼容性”和“目标兼容性”设置为“1.8 (Java 8)”。按“OK”并将项目与Gradle同步。

设置sourceCompatibility = javaverse。VERSION_1_8启用了糖化,但它目前无法糖化Kotlin编译器使用的所有Java 8特性。

修复-设置kotlinOptions。jvmTarget到javaverse。应用模块Gradle中的VERSION_1_8会修复这个问题。

使用Java 8语言特性: 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"
  }
}

在我的案例中,文件>设置> Kotlin编译器>目标JVM版本> 1.8

对我来说,从实现'org.jetbrains.kotlin:kotlin-stdlib:1.5.30'到实现'org.jetbrains.kotlin:kotlin-stdlib:1.4.32'