Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OkHttp 4.0.0 require JVM target 1.8?

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.

like image 762
Jozua Avatar asked Jun 27 '19 09:06

Jozua


1 Answers

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'
}
like image 108
Jozua Avatar answered Oct 22 '22 10:10

Jozua