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

Last updated June 27, 2023 at 08:09 AM

Resolution of 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.

You develop an android application or you update your project. At runtime you encounter a major problem. The error message you find is as follows:

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 our case, this error is caused when we initialize our view model with the new invocation method proposed by google.

private val viewModel: MainViewModel by viewModels ()

In this article we will give you the solution that allowed us to solve the problem.

Solution for 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

To solve this problem you have to modify the gradle. The problem seems to show us that there is a conflict of versions. In your gradle, edit the file to look like this.

compileOptions {sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8} kotlinOptions {jvmTarget = JavaVersion.VERSION_1_8}

Run the solution and the error should normally go away.

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
Image by fotomecky from Pixabay

ON THE SAME TOPIC