Reputation: 641
I have been following this guide by CodeLabs and on this section it shows using the 'suspend' keyword in the DAO methods but when I do it I get this error:
error: To use Coroutine features, you must add `ktx` artifact from Room as a dependency. androidx.room:room-ktx:<version>
public abstract java.lang.Object deleteAll(@org.jetbrains.annotations.NotNull()
public abstract java.lang.Object insert(@org.jetbrains.annotations.NotNull()
^
I checked online but people are saying that you can't use coroutines in with DAO methods.
I also added all the build.gradle imports that come before this step here.
Upvotes: 3
Views: 1645
Reputation: 4230
The issue started after migration from Groovy
to Kotlin DSL
.
I have tried many combinations between Kotlin, Room, and Coroutines versions, but it didn't help.
My workaround was to upgrade Room to the latest beta version, 2.6.0-beta01
.
Upgrading to beta was not anything critical in my case, but I would not recommend it for some production fixes.
Upvotes: 0
Reputation: 641
Okay, I found out what was the issue. Even though I added the coroutine files to the build.grade files, I needed to add Room's specific coroutines file as well which is:
implementation "androidx.room:room-ktx:2.2.5"
This would be to use coroutines with DAO methods.
I was confused as I thought I added all the necessary files in the previous step.
Upvotes: 7