2

Recently, I was trying to create a Java/Kotlin module for my Android application. When I was creating Retrofit Interceptor, there was an error saying:

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.

Here is the screen shot of the exact error:

enter image description here

I know how to set -jvm-target for my Android module. But I am not able to find an answer for how to set it in Java/Kotlin module.


Here is what I have already tried:

[Solution 1 (Not Working)]

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

compileKotlin {
    targetCompatibility(JavaVersion.VERSION_1_8)
}

[Solution 2 (Not Working)]

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toString()
}

Above code gave me following error:

Could not find method kotlinOptions() for arguments

Dhaval
  • 2,724
  • 2
  • 24
  • 33

2 Answers2

7

I have the following in the build script for my Kotlin module, which works for my project:

apply plugin: 'kotlin'

compileKotlin {
    kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}

dependencies {
    // your dependencies...
}
Martin
  • 1,775
  • 1
  • 13
  • 10
-2

New gradle version support like this

compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
Vishal Patel
  • 2,931
  • 3
  • 24
  • 60