Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

JVM target error #76

Closed
avjiang opened this issue Nov 26, 2019 · 12 comments
Closed

JVM target error #76

avjiang opened this issue Nov 26, 2019 · 12 comments
Assignees

Comments

@avjiang
Copy link

avjiang commented Nov 26, 2019

Hi, i am facing problem after updated IntelliJ. I also have updated my kotlin version to 1.3.60

IntelliJ IDEA 2019.2.1 (Community Edition)
Build #IC-192.6262.58, built on August 20, 2019
Runtime version: 11.0.3+12-b304.39 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Previous version i never face any issue, but in this build, i face this error. Now I am using version 1.8.0

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

FAILURE: Build failed with an exception.

Here is the code in my commonMain folder

var timeZone = TimeSpan((8.hours).milliseconds)

I have changed my project JVM version setting to 1.6.
image

Is there anything that I have to do to solve this issue? Hopefully you can guide me on this. Thanks!

@soywiz
Copy link
Collaborator

soywiz commented Dec 1, 2019

I started to use Target JVM version 1.8

@avjiang
Copy link
Author

avjiang commented Dec 2, 2019

Is there any thing I need to adjust in my side?

@soywiz
Copy link
Collaborator

soywiz commented Dec 2, 2019

@avjiang
Copy link
Author

avjiang commented Dec 4, 2019

Hi, i am still facing the issue. Please enlighten me. Below is my settings

apply plugin: 'kotlin-multiplatform'

kotlin {
  jvm {
    compilations.main.kotlinOptions {
        // Setup the Kotlin compiler options for the 'main' compilation:
        jvmTarget = "1.8"
    }

    compilations.main.compileKotlinTask // get the Kotlin task 'compileKotlinJvm'
    compilations.main.output // get the main compilation output
    compilations.test.runtimeDependencyFiles // get the test runtime classpath
  }

// Configure all compilations of all targets:
targets.all {
    compilations.all {
        kotlinOptions {
            allWarningsAsErrors = true
        }
    }
 }
}

sourceSets {
    commonMain {
        dependencies {
            implementation "com.soywiz.korlibs.klock:klock:$klockVersion" // 1.8.0
        }
    }
}

kotlin version is 1.3.60

@avjiang
Copy link
Author

avjiang commented Jan 7, 2020

Hi @soywiz, is there any update about this issue?

I have tried to use the 1.8.0 library version with kotlin version = 1.3.60, but still encounter JVM target issue. I did not face any problem below version 1.8.0. And I have set the jvm target to 1.8 as well in the build.gradle. The target JVM version in Settings -> Kotlin Compiler also has been set to 1.8. And on top of that I have clean reinstalled the Android Studio as well.

image

I am facing the JVM target error when I want to run my CommonTest file. However, i can successfully exported my multiplatform project to iOS. So basically I have to use 1.7.0 version for my Kotlin Multiplatform project testing, and use the version 1.8.0 to export it as iOS framework.

This is my java -version

 Java version "11.0.2" 2019-01-15 LTS
 Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
 Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

Hopefully you can help me on this issue... Thanks

@soywiz
Copy link
Collaborator

soywiz commented Jan 7, 2020

You have to set the kotlinOptions.jvmTarget on your build.gradle file to "1.8".

Like here:
https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin/blob/7373efde446827e965d92c6a61bf8d00637e22bc/src/main/kotlin/com/soywiz/korlibs/targets/JVM.kt#L16

@avjiang
Copy link
Author

avjiang commented Jan 7, 2020 via email

@soywiz
Copy link
Collaborator

soywiz commented Jan 7, 2020

Can you generate a small project reproducing the issue in a repo or a zip file? It should work. But if it doesn't I'' investigate it

@avjiang
Copy link
Author

avjiang commented Jan 7, 2020

Noted. I will provide u a sample application soon. Ty in advance!

@avjiang
Copy link
Author

avjiang commented Jan 8, 2020

hi @soywiz , I Have attached a sample app. Thanks!

sample_app.zip

@soywiz soywiz self-assigned this Jan 8, 2020
@soywiz
Copy link
Collaborator

soywiz commented Jan 22, 2020

Sorry for the huge delay. I didn't know your problem was with the android. The jvm config is for jvm desktop. You have to specify kotlinOptions.jvmTarget for android too:

Change:

jvm("android")

with

jvm("android") {
    compilations.getting {
        kotlinOptions {
            // Setup the Kotlin compiler options for the 'main' compilation:
            jvmTarget = "1.8"
        }
    }
}

@soywiz soywiz closed this as completed Jan 22, 2020
@avjiang
Copy link
Author

avjiang commented Jan 23, 2020

hi @soywiz

Since our current project is using groovy, i tried to find proper syntax to it and i come out with below settings

jvm("android") {
        compilations.main.kotlinOptions {
            jvmTarget = "1.8"
        }
    }

and seems like it doesn't throw the jvm target error anymore. I tried to get you sample app by using groovy, but the tutorial is using kotlin, not groovy anymore.

So i guess it has been fixed now. Thank you so much for your help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants