0

I am trying to use the Android dependency androidx.fragment:fragment-ktx:1.2.2 to be able to load ViewModels in fragments but I am getting an error when trying to use viewModels() saying

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

Searching that I found that in the android section of the build.gradle you need to put in the kotlinOptions

kotlinOptions {jvmTarget = '1.8'}

but when building I get an error

Could not find method kotlinOptions() for arguments

When I do this in a normal Android project it works fine because I assume its part of the kotlin-android plugin.

How do I use this in kotlin multiplatform?

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • See my post for the actual solution to this: https://stackoverflow.com/questions/67009242/how-to-configure-kotlin-jvmtarget-in-a-multiplatform-android-module – John Rayner-Hilles Apr 09 '21 at 16:39

1 Answers1

1

Ended up I my imports were wrong, I needed import

import org.koin.androidx.viewmodel.ext.android.viewModel

then all I had to do was

val viewModel: MyViewModel by viewModel<MyViewModel>()
tyczj
  • 71,600
  • 54
  • 194
  • 296