Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 the above code always give me this 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?

like image 675
user842225 Avatar asked Dec 26 '19 13:12

user842225


1 Answers

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

kotlinOptions {
    jvmTarget = "1.8"
}
like image 83
Md. Asaduzzaman Avatar answered Nov 05 '22 23:11

Md. Asaduzzaman