简体   繁体   English

kotlin 多平台项目中的 kotlinOptions

[英]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我正在尝试使用 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.无法将使用 JVM 目标 1.8 构建的字节码内联到使用 JVM 目标 1.6 构建的字节码中。 Please specify proper '-jvm-target' option请指定正确的“-jvm-target”选项

Searching that I found that in the android section of the build.gradle you need to put in the kotlinOptions搜索我发现在build.gradleandroid部分你需要放入kotlinOptions

kotlinOptions {jvmTarget = '1.8'}

but when building I get an error但是在构建时出现错误

Could not find method kotlinOptions() for arguments找不到参数的方法 kotlinOptions()

When I do this in a normal Android project it works fine because I assume its part of the kotlin-android plugin.当我在普通的 Android 项目中执行此操作时,它工作正常,因为我假设它是kotlin-android插件的一部分。

How do I use this in kotlin multiplatform?我如何在 kotlin 多平台中使用它?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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