简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM