7
votes

Is OkHttp 4.0.0 intentionally incompatible with jvm target 1.6? Upgrading from OkHttp 3.12.0 to 4.0.0 I run into the following build failure.

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

On further inspection I found the root cause to be the Interceptor interface having a static method (function inside companion object). The upgrade guide does not mention this backward incompatibility leading me to believe it's unintentional.

2

2 Answers

16
votes

Found a blog post with some explanations. Since OkHttp 3.13.1 JVM target 1.8 is required. The suggested change is:

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  ...
}

I found that it still fails. Adding one more instruction finally fixes the build.

kotlinOptions {
    jvmTarget = '1.8'
}
0
votes

I found the simplest solution for this is to do the following:

Groovy:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions.jvmTarget = '1.8'
}

Kotlin (kts):

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}