最近,我尝试为我的 Android 应用程序创建一个 Java/Kotlin 模块。
当我创建 Retrofit Interceptor
时,出现错误:
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option.
这是确切错误的屏幕截图:
我知道如何为我的 Android 模块设置 -jvm-target
。但我无法找到如何在 Java/Kotlin 模块中设置它的答案。
这是我已经尝试过的:
[解决方案 1(不起作用)]
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileKotlin {
targetCompatibility(JavaVersion.VERSION_1_8)
}
[解决方案 2(不起作用)]
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
上面的代码给了我以下错误:
Could not find method kotlinOptions() for arguments
最佳答案
我的 Kotlin 模块的构建脚本中有以下内容,适用于我的项目:
apply plugin: 'kotlin'
compileKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
dependencies {
// your dependencies...
}
关于Android Studio - 如何在 Java/Kotlin 模块中指定 "-jvm-target"选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61662162/