kotlin多平台项目中的kotlinOptions [英] kotlinOptions in kotlin multiplatform project

查看:859
本文介绍了kotlin多平台项目中的kotlinOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android依赖项 androidx.fragment:fragment-ktx:1.2.2 能够分段加载 ViewModels ,但出现错误尝试使用 viewModels()

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

无法将使用JVM target 1.8构建的字节码内联到以下字节码中用JVM target 1.6构建的.请指定正确的"-jvm-target"选项

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.gradle android 部分中放入 kotlinOptions

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

kotlinOptions {jvmTarget = '1.8'}

但是在构建时出现错误

找不到用于参数的方法kotlinOptions()

Could not find method kotlinOptions() for arguments

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

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

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

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

那我要做的就是

val viewModel: MyViewModel by viewModel<MyViewModel>()

这篇关于kotlin多平台项目中的kotlinOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆