Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Completable in Room dao interface

I'm trying to use Completable in Dao class on @Insert annotated methods but when tried to compile the project, I've got this error:

error: Methods annotated with @Insert can return either void, long, Long, long[], Long[] or List<Long>.
public abstract io.reactivex.Completable insert(@org.jetbrains.annotations.NotNull()

Here my related codes:

@Insert
fun insert(kanal: Kanal): Completable
@Update
fun update(kanal: Kanal): Completable
@Delete
fun delete(kanal: Kanal): Completable

And my dependencies:

def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
kapt "android.arch.persistence.room:compiler:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

According to this link it's supported by Room.

like image 870
RuNo280 Avatar asked Dec 03 '18 15:12

RuNo280


Video Answer


2 Answers

@Insert, @Update, and @Delete methods: Room 2.1.0 and higher supports return values of type Completable, Single, and Maybe.

Update your room from 1.1.1 to 2.1.0 or higher and it will work.

like image 104
musooff Avatar answered Oct 06 '22 00:10

musooff


Completable isn't working with @Insert in 1.1.1 version of Room. You have to use 2.1.0 version or higher which is only available in Android X.

Make sure to use these dependencies instead of regular android.arch.persistence.room:

def room_version = "2.2.0-alpha02"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // For Java use annotationProcessor instead of kapt
implementation "androidx.room:room-rxjava2:$room_version"
testImplementation "androidx.room:room-testing:$room_version"

Here's the link that provides all of the Android X dependencies of Room.

like image 33
twenk11k Avatar answered Oct 06 '22 01:10

twenk11k