10

What is the difference between rxjava2 dependency and rxkotlin dependency. If I'm using rxkotlin dependency, should i need to add rxjava2 dependency along with that.

implementation 'io.reactivex.rxjava2:rxkotlin:x.y.z'
// do i need to add the below dependencies also?
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77

4 Answers4

11

the thing is RX stands for Reactive Extensions , and Rx Java , Rx Kotlin or Rx Swift all are the implementation of Reactive Extensions in that particular language.

What is RxJAVA? RxJava is a Java VM implementation of Reactive Extensions. where we can create asynchronous data stream on any thread, transform it and these asynchronous data streams can be consumed by Observers on any thread.

What is RxKotlin? RxKotlin is a Kotlin implementation of Reactive Extensions.

What is RxAndroid? It is specific to Android Platform with some more added classes on top of RxJava.

for more details , visit my collection of rxjava simple examples https://github.com/myJarvis/Intro_to_RxJava .

and to more clarify , RxKotlin has some convenient extension functions which comes with Kotlin.

You can either use {RxJava & RxAndroid} or {RxKotlin}

You can use RxJava with Kotlin out-of-the-box

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
  • Ok, then do i need to add both rxjava2 along with rxkotlin @Thunder – Manoj Perumarath Apr 12 '19 at 05:56
  • 1
    see , the thing is RX stands for Reactive Extensions , and Rx Java , Rx Kotlin or Rx Swift all are the implementation of Reactive Extensions in that particular lang – Sachin Rajput Apr 12 '19 at 05:56
  • yes you need to add these both (if you are working on android project) implementation "io.reactivex.rxjava2:rxandroid:${rxAndroid}" implementation "io.reactivex.rxjava2:rxjava:${rxJava}" – Sachin Rajput Apr 12 '19 at 05:57
  • you can visit https://github.com/myJarvis/Intro_to_RxJava . , you will get a basic understanding of how to start working with these two. – Sachin Rajput Apr 12 '19 at 05:58
  • Can you take a look at the answer given by akshay_shahane – Manoj Perumarath Apr 12 '19 at 06:01
  • @ManojPerumarath mate i am using rxjava in our android app which is used by 2.5million :) whole code base is writtern in rxjava and kotlin – Sachin Rajput Apr 12 '19 at 06:02
  • you can start coding after adding these two dependencies , implementation "io.reactivex.rxjava2:rxandroid:${rxAndroid}" implementation "io.reactivex.rxjava2:rxjava:${rxJava}". for code example visit here https://github.com/myJarvis/Intro_to_RxJava. – Sachin Rajput Apr 12 '19 at 06:04
  • i added some basic examples here , how u can use Observables and observer and all other rxjava stuff – Sachin Rajput Apr 12 '19 at 06:04
  • 1
    Ok i'll a take look into that – Manoj Perumarath Apr 12 '19 at 06:07
  • "Schedulers are introduced in RxAndroid" No they aren't. http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Scheduler.html RxAndroid only provides some scheduler _implementations_. – Alexey Romanov Apr 12 '19 at 08:31
6

Since Kotlin is 100% interoperable with Java, you can use most Java libraries in your Kotlin projects without any difficulties—and the RxJava library is no exception.

There is a dedicated RxKotlin library, which is a Kotlin wrapper around the regular RxJava library. This wrapper provides extensions that optimize RxJava for the Kotlin environment and can further reduce the amount of boilerplate code you need to write.

If you are using rxkotlin you just need to add the following line

implementation 'io.reactivex:rxkotlin:x.y.z'

and if you want to use rxjava2 you need to include the other dependencies i.e

implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

but if you are using Kotlin as your programming language I will recommend you using rxkotlin

More detail refer to this link

Akshay Katariya
  • 1,464
  • 9
  • 20
  • I understood that, but this doesn't answer my question – Manoj Perumarath Apr 12 '19 at 05:52
  • see you can use RxJava with Kotlin out-of-the-box , no need to use rxkotlin if you are using rxjava , that is also fine , when you will write code , extension function will be available bcs you are already using kotin with rxjava – Sachin Rajput Apr 12 '19 at 06:25
  • your answer itself says this RxKotlin library, which is a Kotlin wrapper around the regular RxJava library . – Sachin Rajput Apr 12 '19 at 06:28
  • 2
    You don't need to add `rxjava` exactly because `rxkotlin` is a wrapper around `rxjava` and will bring it in automatically. – Alexey Romanov Apr 12 '19 at 08:26
4

As you can see at https://mvnrepository.com/artifact/io.reactivex.rxjava2/rxkotlin/2.3.0, rxkotlin depends on rxjava. So it's automatically added as a transitive dependency unless you specifically exclude it.

Unsurprisingly, rxkotlin does not depend on rxandroid so you do need to add that if you want to use it. Both rxandroid and rxkotlin use the same rxjava types, so they can interoperate freely.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
0

The predominant library in this Android development is RxJava. Since Kotlin is fully interoperable with Java libraries, RxKotlin is only a thin wrapper over the original RxJava.

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42