Why I still get “Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6”

*爱你&永不变心* 提交于 2020-01-04 05:55:09

问题


I am developing an Android project with Kotlin and Dagger 2. I have a NetworkModule it is supposed to provide a singleton instance of Retrofit. in which I define all those provider functions.

All code snippet below are inside NetworkModule :

@Module
object NetworkModule {
   ...
}

I want to provide HttpRequestInterceptor , this is what I tried:

@Provides
@JvmStatic
internal fun provideHttpRequestInterceptor(): Interceptor {
    // compiler error: 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

    return Interceptor { chain ->
        val original = chain.request()
        val requestBuilder = original.newBuilder()
        val request = requestBuilder.build()
        chain.proceed(request)
        }
}

But above code always give me compiler error 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.

In my build.gradle I have specified

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

I have two questions now:

  1. What is built with jvm 1.6 and 1.8 respectively? How this could happen (please use example to explain) ?

  2. As you can see in my build.gradle I already declared build target is JVM 1.8. Why I still get this error?


回答1:


Add kotlinOptions and set jvmTarget to 1.8 in your build.gradle file to resolve the problem

kotlinOptions {
    jvmTarget = "1.8"
}


来源:https://stackoverflow.com/questions/59488983/why-i-still-get-cannot-inline-bytecode-built-with-jvm-target-1-8-into-bytecode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!