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:
What is built with jvm 1.6 and 1.8 respectively? How this could happen (please use example to explain) ?
As you can see in my build.gradle I already declared build target is JVM 1.8. Why I still get this error?
Add kotlinOptions
and set jvmTarget
to 1.8 in your build.gradle
file to resolve the problem
kotlinOptions {
jvmTarget = "1.8"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With