Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio throws build error in Kotlin project which calls static method in java interface

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'

Error

I have the following in my build.gradle,

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_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.

Kotlin Compiler Settings

Android Studio version: 3.0.1

like image 271
Raj Avatar asked Feb 23 '18 17:02

Raj


1 Answers

The compileOptions section in build.gradle affects the Java compiler, not the Kotlin compiler. To set the target JVM version for the Kotlin compiler, use the following block:

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

See the documentation for more information.

like image 59
yole Avatar answered Sep 23 '22 13:09

yole