When trying to run the Example CorDapp (GitHub CorDapp) via IntelliJ, I receive the following error:
Cannot inline bytecode built with JVM target 1.8 int
If you have many sourcesets/modules it can be cumbersome to configure the jvmTarget for each of them separately.
You can configure the jvmTarget for all of them at once like so:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
This snippet can be used on top level of your gradle.build file
After modifying the gradle file Reimport All Gradle Imports
.
To check if it worked, open Project Structure
and verify that IntelliJ correctly assigned JVM 1.8
to all Kotlin-Modules. It should look like this:
I would not recommend changing the platform directly in IntelliJ, because anyone else cloning your project for the first time is likely to face the same issue. Configuring it correctly in gradle has the advantage that IntelliJ is going to behave correctly for them right from the start.
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
please add this code to android section inside your app/build.gradle
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
The next solution helped me. Add to build.gradle
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
You can fix this issue as follows:
Build, Execution, Deployment
> Compiler
> Kotlin Compiler
BUT Other Settings
> Kotlin compiler
if Android Studio > 3.4
Target JVM version
to 1.8
Apply
if you are in android project
in your app's build.gradle under android{}
android{
//other configs...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}