Why kotlin gradle plugin cannot build with 1.8 target?
It turned out that it was my kotlin compiler configuration in intellij settings. In Settings > Build, Execution, Deployment > Compiler > Kotlin Compiler
a setting called Target JVM version
should have been set to 1.8.
There is a gradle property used by Kotlin plugin which can be used. When you add
kotlin.setJvmTargetFromAndroidCompileOptions = true
to your gradle.properties
file.
When you have this configuration on your build.config
android{
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
problem sould be solved.
I think this could be helpful for those using Android Studio 3.2 on Mac.
To change the Kotlin Compiler Target JVM version you should go to Android Studio -> Preferences -> Kotlin Compiler and then change the Target JVM version choosing from the dropdown.
Anyway, I'm still getting the following error
Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8'
SOLVED
Adding the following to my build.gradle solved the problem:
android {
kotlinOptions {
jvmTarget = '1.8'
}
}
About this and other Gradle configuration options: https://kotlinlang.org/docs/reference/using-gradle.html
With Kotlin Gradle DSL:
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
(kotlinOptions as KotlinJvmOptions).apply {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}