当试图通过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.toString()
    }
}

GL

使用Java 8语言特性

其他回答

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

这有助于我的项目构建,将此添加到模块构建。gradle文件:

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(同时最好检查使用项目设置选项)

2020年2月 android 3.4 + 去文件->设置-> Kotlin编译器->目标JVM版本>设置为1.8,然后确保做文件->同步项目与Gradle文件 或者将此添加到android block中的build.gradle(module:app):

kotlinOptions {
           jvmTarget = "1.8"
         }

您应该在build.gradle中配置如下内容

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}