RxKotlin with Retrofit

In Android, we can use RxAndroid in addition to RxKotlin for added Android flavors and benefits, and Retrofit supports them as well.

So, let's start by modifying our build.gradle in favor of ReactiveX. Add the following dependencies to the app level build.gradle:

    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0 ' 
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' 
    implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0' 

The first one will provide Retrofit 2 Adapters for RxJava 2, while the following two add RxAndroid and RxKotlin to the project.

Note that RxKotlin is a wrapper on top of RxJava, so adapters for RxJava 2 will work perfectly with RxKotlin 2.

Now that we have added the dependencies, let's move ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.