Android Studio在Kotlin项目中引发构建错误,该项目在Java接口中调用静态方法 [英] Android Studio throws build error in Kotlin project which calls static method in java interface
问题描述
我在Android Studio中有一个Kotlin项目.我正在从Kotlin代码在Java接口中调用静态方法.构建因错误而失败,
I have a Kotlin project in Android Studio. I am calling a static method in Java interface from the Kotlin code. The build fails with the error,
Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
我的 build.gradle 中有以下内容,
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
我还在Kotlin编译器设置中将Target JVM版本更改为1.8.尽管如此,该构建仍会引发错误.还尝试了使缓存无效并重新启动.
I have also changed the Target JVM version to 1.8 in Kotlin compiler settings. Still, the build throws the error. Also tried Invalidating cache and restarting.
Android Studio版本:3.0.1
Android Studio version: 3.0.1
推荐答案
在android gradle中设置Kotlin编译选项的正确方法. 对您的应用程序级别进行这些更改 Build.gradle
Proper way to set Kotlin compile options in android gradle. Make these changes to your app level Build.gradle
更改
实现"org.jetbrains.kotlin:kotlin-stdlib-jre7:$ kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
到
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
然后编写此任务
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.1'
languageVersion = '1.1'
}
}
就在下面(不一定)
repositories {
mavenCentral()
}
有关详细信息,请参见此处
For details, refer here
这篇关于Android Studio在Kotlin项目中引发构建错误,该项目在Java接口中调用静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!