Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJava 3 support for Room

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.

like image 377
Fire_Icicle Avatar asked Jun 14 '20 11:06

Fire_Icicle


2 Answers

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

like image 187
sergiy tikhonov Avatar answered Nov 15 '22 01:11

sergiy tikhonov


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.

like image 35
Hans Wurst Avatar answered Nov 15 '22 00:11

Hans Wurst