Fire_Icicle
Fire_Icicle

Reputation: 121

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.

Upvotes: 6

Views: 5334

Answers (4)

Ribas
Ribas

Reputation: 1

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

Upvotes: 0

sergiy tykhonov
sergiy tykhonov

Reputation: 5103

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

Upvotes: 8

MihaiW
MihaiW

Reputation: 490

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.

Upvotes: 2

Sergej Isbrecht
Sergej Isbrecht

Reputation: 4002

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.

Upvotes: 3

Related Questions