9

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?

Vsevolod
  • 332
  • 4
  • 10
  • For my insert & delete functions i just removed the `suspend` keyword. For my Querys i used a return type of `Flow`. However, this just removing the suspend feels like cheating :( – m.reiter Nov 24 '21 at 14:37
  • Yes. I've removed it too. I could not find right way. What was changed. How to deal with it. – Vsevolod Nov 24 '21 at 15:35

2 Answers2

8

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.

Abed
  • 3,999
  • 1
  • 17
  • 28
2

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

Abed
  • 3,999
  • 1
  • 17
  • 28
  • 1
    But why do we have to go through breaking changes like this every time the language is updated? That's the reason why you cannot accept any AS update with confidence. Always a risk of breaking something that was working fine before. – Thilaw Fabrice Jan 06 '22 at 09:06
  • Agree, we are always afraid of upgrading, we want to spend time developing, not how to overcome those breaking changes! – Abed Jan 06 '22 at 18:46