简体   繁体   English

kotlin 升级到 1.6.0 后如何在 Room Dao 中使用挂起修饰符?

[英]How to use suspend modifier in Room Dao after kotlin upgrade to 1.6.0?

Upgrading kotlin to 1.6.0 causes Room Dao suspend modifier to break build project with error: "Not sure how to handle query method's return type........".将 kotlin 升级到 1.6.0 会导致 Room Dao 挂起修改器中断构建项目并出现错误:“不确定如何处理查询方法的返回类型......”。

Are there(here) any solutions other than a workaround for running Dao functions withContext(Disapatchers.IO) in repository?除了在存储库中运行 Dao 函数 withContext(Disapatchers.IO) 的解决方法之外,还有其他解决方案吗?

I faced the same issue yesterday with the upgrade of Kotlin 1.6.0.我昨天在升级 Kotlin 1.6.0 时遇到了同样的问题。

My working project started to fail, same error messages.我的工作项目开始失败,同样的错误消息。

After searching in some other forums someone mentioned to change roomVersion to " 2.4.0-beta02 ".在其他一些论坛中搜索后,有人提到将 roomVersion 更改为“ 2.4.0-beta02 ”。 And.. surprisingly it worked.而且......令人惊讶的是它起作用了。 At least it compiled without any more issues.至少它编译没有任何问题。

Try it, hopefully it will work for you too.试试吧,希望它也对你有用。

Mine is defined in a variable:我的定义在一个变量中:

def roomVersion = "2.4.0-beta02" def roomVersion = "2.4.0-beta02"

So the rest of the dependencies for Room should take advantage of this change.因此,Room 的依赖项的 rest 应该利用此更改。

The new Kotlin version needs room 2.4.0 at least (In the meantime it's in RC state) to support the language so if you want to use in your project kotlin 1.6.0 you have to upgrade room to use 2.4.0 (also target Android API 31).新的 Kotlin 版本至少需要2.4.0空间(同时它处于 RC 状态)以支持该语言,所以如果你想在项目中使用 kotlin 1.6.0 ,你必须升级空间才能使用2.4.0 (也是目标Android API 31)。

Room 2.4.0 changes 房间 2.4.0 的变化

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

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