4

In 2.1 Room added support for coroutines, but I can't get it working. It should be as easy as adding the dependency but somehow I'm overlooking something.

In my build.gradle I got the dependencies for coroutines, room and room-coroutines

dependencies { 
    def room_version = "2.2.0-beta01"
    // Room components
    implementation "android.arch.persistence.room:runtime:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    androidTestImplementation "android.arch.persistence.room:testing:$room_version"
    def coroutines_version = "1.1.1"
    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
}

I allready tryed resyncing gradle, cleaning and rebuilding the project.

In my Doa i have methods like the following

@Dao
interface PlanDao {
    @Insert
    suspend fun insertVerPlan(verPlan: SqlVerPlan)
}

When trying to build the project Room doesn't know how to handle the suspending functions and the following error occurs:

error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> p1);
                                                        ^

error: Methods annotated with @Insert can return either void, long, Long, long[], Long[] or List<Long>.
    public abstract java.lang.Object insertVerPlan(@org.jetbrains.annotations.NotNull()
                                     ^

I seriously don't know what I'm missing and I can't find anyone with the same problem since the new Room version.

1
  • Hello, do not attach a link to git, I want to see how you work with coroutine Commented Nov 5, 2019 at 16:01

1 Answer 1

4

You're mixing different versions of the room library.

android.arch.persistence.room:runtime should be androidx.room:room-runtime

android.arch.persistence.room:compiler should be androidx.room:room-compiler

android.arch.persistence.room:testing should be androidx.room:room-testing

as per Room#Declaring dependencies

Since you're using the old coordinates for the compiler it does not know about the suspend support.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.