Reputation: 583
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.
Upvotes: 8
Views: 5301
Reputation: 1180
above didnt work for me, here is what i used in oder fix it
def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"
Upvotes: 0
Reputation: 21
if you dont want to update the Room's Version, you can try to make a Completable return like this:
fun insertSomthing():Completable{
return Completable.fromAction{
insert(kanal: Kanal)
}.subscribeOn(Schedulers.io())
}
Upvotes: 2
Reputation: 577
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.
Upvotes: 2
Reputation: 6852
@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.
Upvotes: 14