当试图通过IntelliJ运行示例CorDapp (GitHub CorDapp)时,我收到以下错误:
不能将使用JVM目标1.8构建的字节码内联为当前的字节码 使用JVM目标1.6构建
如何修改IntelliJ设置,使所有字节码都使用相同的JVM目标构建?
当试图通过IntelliJ运行示例CorDapp (GitHub CorDapp)时,我收到以下错误:
不能将使用JVM目标1.8构建的字节码内联为当前的字节码 使用JVM目标1.6构建
如何修改IntelliJ设置,使所有字节码都使用相同的JVM目标构建?
当前回答
请将此代码添加到app/build.gradle中的android部分
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
其他回答
使用Kotlin Gradle DSL,这为我解决了这个问题。我把这个加到build.gradle.kts里了。 这是在乔尔的回答之外的
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
如果你使用Eclipse,假设你下载了Kotlin插件:
右键单击项目->属性-> Kotlin Compiler ->启用项目特定设置-> JVM目标版本“1.8”
您可能需要同时设置compileKotlin和compileTestKotlin。 这适用于gradle 6.5.1。
compileKotlin {
kotlinOptions {
languageVersion = "1.2"
apiVersion = "1.2"
jvmTarget = "1.8"
javaParameters = true // Useful for reflection.
}
}
compileTestKotlin {
kotlinOptions {
languageVersion = "1.2"
apiVersion = "1.2"
jvmTarget = "1.8"
javaParameters = true // Useful for reflection.
}
}
如果以上答案都无效,您可以在kotlin dsl中执行此操作
android {
...
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
在我的例子中,jvmTarget已经在构建中设置了。Gradle文件如下。
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
但我的问题依然存在。 最后,在Preferences > Other Settings > Kotlin Compiler >目标JVM版本后,将目标JVM版本从1.6更改为1.8。见附图,