Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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........".

Are there(here) any solutions other than a workaround for running Dao functions withContext(Disapatchers.IO) in repository?

like image 917
Vsevolod Avatar asked Nov 24 '21 10:11

Vsevolod


2 Answers

I faced the same issue yesterday with the upgrade of 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". 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"

So the rest of the dependencies for Room should take advantage of this change.

like image 130
Jorge Flores Avatar answered Nov 15 '22 10:11

Jorge Flores


The new Kotlin compiler (aka 1.6.+) needs room version 2.4.0 at least to support the language. So Upgrade your room dependency to 2.4.0.

And since you are using the version of room you also have to target Android API 31.

Room 2.4.0 changes

like image 36
Abed Avatar answered Nov 15 '22 12:11

Abed