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

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

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


当前回答

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

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"
        }
    }

其他回答

如果你使用Eclipse,假设你下载了Kotlin插件:

右键单击项目->属性-> Kotlin Compiler ->启用项目特定设置-> JVM目标版本“1.8”

在我的例子中,只是像这样更改目标JVM版本:File > Setting > Kotlin Compiler > Target JVM Version > 1.8并没有帮助。但是,它解决了编译时错误。但在运行时失败。

我还必须在应用程序构建中添加以下内容。Gradle文件使它工作。

 android {
     // Other code here...
     kotlinOptions {
        jvmTarget = "1.8"
     }
 }

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

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"
        }
    }

当其他解决方案不适合你时(在编译器设置上更改JVM版本并将jvmTarget添加到build.gradle中),因为你的.iml文件试图强制它们的配置,你可以从项目设置中更改目标平台。

打开文件>项目结构 进入项目设置下的Facets 如果它是空的,然后点击小的+按钮 单击您的Kotlin模块/模块 将目标平台更改为JVM 1.8(同时最好检查使用项目设置选项)

给Eclipse用户的另一个提示。在仔细检查了其他用户指出的jvm目标设置后,我仍然有同样的问题,这是由于缺少Kotlin运行时库造成的。例如,当使用spring initializr创建一个项目时,它不会自动添加。要添加它:右键单击您的项目->构建路径->添加库…->用户库,并添加org.jetbrains.kotlin.core.KOTLIN_CONTAINER

确保你刷新你的gradle项目之后(右击-> gradle ->刷新gradle项目)