为什么我仍然会“无法将使用JVM目标1.8构建的字节代码内联到使用JVM目标1.6构建的字节代码中" [英] Why I still get "Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6"

查看:314
本文介绍了为什么我仍然会“无法将使用JVM目标1.8构建的字节代码内联到使用JVM目标1.6构建的字节代码中"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Kotlin和Dagger 2开发一个Android项目.我有一个NetworkModule,它应该提供Retrofit的单例实例.在其中定义了所有这些提供程序功能.

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.

以下所有代码段均位于NetworkModule内:

All code snippet below are inside NetworkModule :

@Module
object NetworkModule {
   ...
}

我想提供HttpRequestInterceptor,这是我尝试的方法:

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)
        }
}

但是上面的代码总是给我编译器错误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.

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.

在build.gradle中,我已指定

In my build.gradle I have specified

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

我现在有两个问题:

  1. jvm 1.6和1.8分别构建了什么?怎么发生(请使用示例进行解释)?

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

您可以在我的build.gradle中看到,我已经声明了构建目标为JVM 1.8.为什么我仍然会收到此错误?

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

推荐答案

添加kotlinOptions并将jvmTarget设置为build.gradle文件中的1.8,以解决问题

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

kotlinOptions {
    jvmTarget = "1.8"
}

这篇关于为什么我仍然会“无法将使用JVM目标1.8构建的字节代码内联到使用JVM目标1.6构建的字节代码中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆