Search code examples
androidkotlinkotlin-multiplatform

kotlinOptions in kotlin multiplatform project


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?


Solution

  • 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>()