kotlin 多平台项目中的 kotlinOptions

kotlinOptions in kotlin multiplatform project

我正在尝试使用 Android 依赖项 androidx.fragment:fragment-ktx:1.2.2 以便能够在片段中加载 ViewModels 但是在尝试使用 viewModels() 时出现错误说

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

搜索我发现在 build.gradleandroid 部分你需要输入 kotlinOptions

kotlinOptions {jvmTarget = '1.8'}

但是在构建时出现错误

Could not find method kotlinOptions() for arguments

当我在正常的 Android 项目中执行此操作时,它工作正常,因为我假设它是 kotlin-android 插件的一部分。

如何在 kotlin 多平台中使用它?

最后我的导入错误,我需要导入

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

那么我所要做的就是

val viewModel: MyViewModel by viewModel<MyViewModel>()