RxJava 3 support for Room
Asked Answered
L

4

6

I am using RxJava3 with Room in my project but I am getting the following error

error: Not sure how to convert a Cursor to this method's return type (io.reactivex.rxjava3.core.Flowable>)

Below is DAO interface method on which I am getting the error

@Query("SELECT * FROM wishlist_table")
Flowable<List<WishListMovie>> getWishList();

I think maybe its because I am using the dependency below in my grade file:

implementation "androidx.room:room-rxjava2:$room_version"

I tried to find the above dependency for RxJava 3 but I was unable to find it.

I want to know how can I use RxJava 3 with Room or should I use RxJava 2 instead in my project.

Lorenzetti answered 14/6, 2020 at 11:5 Comment(0)
H
8

July 22, 2020

In Room 2.3.0-alpha02 was added support for RxJava3 types. Though it's still in alpha, but you can consider this option.

According to release description:

Similar to RxJava2 you can declare DAO methods whose return type are Flowable, Single, Maybe and Completable.
Additionally a new artifact androidx.room:room-rxjava3 is available to support RxJava3

Hasp answered 23/7, 2020 at 22:39 Comment(0)
F
3

Problem

I want to know how can I use RxJava 3 with Room or should I use RxJava 2 instead in my project.

Result

You can not use RxJava3 with Room "room-rxjava2" dependency.

Explanation

RxJava2 and RxJava3 are different. In order to avoid runtime errors (e.g. during linking) RxJava3 chose different packages. This is why the returned type does not match (different package)

Solution

Until there is a room-rxjava3 package you have to use RxJava2 as a dependency.

Workaround

You could checkout room-rxjava2 and change all packages for rxjava3 and compile aginst rxjava3 and then use this package.

File answered 14/6, 2020 at 11:34 Comment(0)
B
2

Currently updating a project and having the same problem.

I'm using room-rxjava2 to generate the DAOs (as before) with RxJava2 types. But for my business logic I'm using https://github.com/akarnokd/RxJavaBridge to convert to RxJava3 types.

Bacchus answered 20/7, 2020 at 16:40 Comment(0)
S
0

Another solution would be not using a reactive type on the Dao and have a reactive wrapper it in a repository

Seriate answered 13/9, 2020 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.