Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

别说谁变了你拦得住时间么 提交于 2019-11-26 23:55:57

问题


When trying to run the Example CorDapp (https://github.com/corda/cordapp-example) via IntelliJ, I receive the following error:

Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

How can I modify the IntelliJ settings so that all the bytecode is built with the same JVM target?


回答1:


app/build.gradle

android {
    ...
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

GL

Source




回答2:


You can fix this issue as follows:

  • Open the IntelliJ preferences
  • Go to Build, Execution, Deployment > Compiler > Kotlin Compiler BUT Other Settings > Kotlin compiler if Android Studio > 3.4
  • Change the Target JVM version to 1.8
  • Click Apply



回答3:


you should configure something like as follows in build.gradle

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}



回答4:


When the other solutions did not work for you (Changing JVM version on Compiler settings and adding jvmTarget into your build.gradle), because of your .iml files trying to force their configurations you can change the target platform from Project Settings.

  • Open File > Project Structure
  • Go to Facets under Project Settings
    • If it is empty then click on the small + button
  • Click on your Kotlin module/modules
  • Change the Target Platform to JVM 1.8 (also it's better to check Use project settings option)



回答5:


In my case, just changingTarget JVM Version like this: File > Setting > Kotlin Compiler > Target JVM Version > 1.8 did not help. However, it does resolved compile time error. But failed at runtime.

I also had to add following in app build.gradle file to make it work.

 android {
     // Other code here...
     kotlinOptions {
        jvmTarget = "1.8"
     }
 }



回答6:


In Android Studio 4.3.2 adding through the below procedure is not working.

  1. Open the IntelliJ preferences
  2. Go to Build, Execution, Deployment > Compiler > Kotlin Compiler BUT Other Settings > Kotlin compiler if Android Studio > 3.4
  3. Change the Target JVM version to 1.8
  4. Click Apply

The reason is, Android studio is unable to add the below code in the module level Gradle file. Please add it manually.

kotlinOptions {
    jvmTarget = "1.8"
}

Just for the addon, search Target JVM version in the android studio search. It will take you directly to the option.




回答7:


As it is written in the using-maven docs from the Kotlin website:

You just have to put <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget> into the properties section of your pom.xml




回答8:


a picture is worth a thousand words




回答9:


For me the reason was this configuration in my build gradle was in some modules and in some it wasnt

android {  
...      
kotlinOptions {
        val options = this as KotlinJvmOptions
        options.jvmTarget = "1.8"
    }
...
android {



回答10:


In my case, I solved this by following these two steps

1. Go to android studio preferences -> other settings -> kotlin compiler -> set Target JVM version = 1.8 
   if it doesn't work then go to the second option.

2. In your module-level build.gradle file add 
   compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }



回答11:


For Gradle with Kotlin language (*.gradle.kts files), add this:

android {
    [...]
    kotlinOptions {
        this as KotlinJvmOptions
        jvmTarget = "1.8"
    }
}



回答12:


In my case File > Setting > Kotlin Compiler > Target JVM Version > 1.8




回答13:


For recent versions of Android Studio, if changing just the Kotlin Target VM version didn't work.

File ➞ Project Structure ➞ Modules (app): set both "Source Compatibility" and "Target Compatibility" to "1.8 (Java 8)". Press "OK" and sync project with Gradle.




回答14:


If you use Eclipse assuming you downloaded the Kotlin plugin:

Right click project -> Properties -> Kotlin Compiler -> Enable project specific settings -> JVM target version "1.8"




回答15:


FYI, if you have other library modules (not app) that have this issue, you need to add that same config in those library modules:

 android {
     kotlinOptions {
        jvmTarget = "1.8"
     }
 }



回答16:


If using Visual Studio Code** with Kotlin extension, go to the plugin management Crtl + Shift + x, type kotlin and click on manage (the little gear) >> Configure Extension Settings

on Kotlin >> Compiler >> Jvm:Target - type the java version. In my situation just typed 1.8

And then restart :-)

** vscode or just 'code' for linux




回答17:


If you are done changing versions and all and still not able to run your code.

Try this.

Create a class like HeaderInterceptor .

 class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response = chain.run {
        proceed(
            request()
                .newBuilder()
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .addHeader(
                    "Authorization",
                    "Bearer" + "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwcm9maWxlX2lkIjo0NDcsImxvY2F0aW9uX2lkIjoxMTgyLCJpc3N1ZWRfZm9yIjoiY3VzdG9tZXIiLCJzdWIiOjY3MSwiaXNzIjoiaHR0cHM6Ly9hcGkubmVvbi1tb2JpbGUuY29tL2FwaS9mMS9maXJlYmFzZS1sb2dpbiIsImlhdCI6MTU2ODE3OTgyMSwiZXhwIjoxNTcwNzcxODIxLCJuYmYiOjE1NjgxNzk4MjEsImp0aSI6ImI1WGNEVDh6TlhTSWprb04ifQ.vNU--vvlz6Qy6qzwooCQxYL2gtB79v0t378qVWXWxcs"
                )
                .build()
        )
    }
}

And now just add it as

.addInterceptor(HeaderInterceptor())

This might help you to save your day.



来源:https://stackoverflow.com/questions/48988778/cannot-inline-bytecode-built-with-jvm-target-1-8-into-bytecode-that-is-being-bui

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