Can't use RxJava with Hengam SDK

Viewed 204

I've recently added Hengam SDK in my project; but unfortunately I can't use RxJava anymore and It causes duplicate exception. It is worth mentioning that prior to adding the SDK to the project everything was working properly.

Here's the stack trace:

Duplicate class io.reactivex.BackpressureStrategy found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Completable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.CompletableEmitter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.CompletableObserver found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.CompletableOnSubscribe found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.CompletableSource found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Emitter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Flowable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Maybe found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.MaybeEmitter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.MaybeObserver found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.MaybeOnSubscribe found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.MaybeSource found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Observable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Observable$1 found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableConverter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableEmitter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableOnSubscribe found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableOperator found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableSource found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.ObservableTransformer found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Observer found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Scheduler found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Scheduler$Worker found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.Single found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.SingleEmitter found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.SingleObserver found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.SingleOnSubscribe found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.SingleSource found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.annotations.CheckReturnValue found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.annotations.NonNull found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.annotations.Nullable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2io.hengam.lib:rxjava:2.2.9)
Duplicate class io.reactivex.disposables.Disposable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.disposables.Disposables found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.CompositeException found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.Exceptions found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.MissingBackpressureException found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.OnErrorNotImplementedException found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.ProtocolViolationException found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.exceptions.UndeliverableException found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.Action found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.BiConsumer found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.BiFunction found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.Consumer found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.Function found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.functions.Predicate found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.internal.functions.Functions found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.observables.GroupedObservable found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.plugins.RxJavaPlugins found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.schedulers.Schedulers found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.schedulers.TestScheduler found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)
Duplicate class io.reactivex.subjects.PublishSubject found in modules rxjava-2.0.4.jar (io.hengam.lib:rxjava:2.0.4) and rxjava-2.2.9.jar (io.reactivex.rxjava2:rxjava:2.2.9)

What's wrong with it? Is there any conflict with the SDK or it needs any additional configuration to use RxJava? Any response would be appreciated...

2 Answers

AFAIK, Hengam has a customized RxJava2 (For keeping SDK final size lower). So if you want to use RxJava2 along with Hengam, you need to exclude it's custom RxJava2 and implement the actual library.

implementation ('io.hengam.lib:base:1.0.8')  {
   exclude group: 'io.hengam.lib', module: 'rxjava'
}

implementation 'io.reactivex.rxjava2:rxjava:2.2.9'

So the io.hengam.lib:rxjava will not be imported to class path and instead, RxJava2 of ReactiveX will be added.

Note:
1. Use RxJava2 version 2.2.9 or higher.
2. The RxJava3 has a different packaging in compare to RxJava2. So make sure you add RxJava2

Hengam reference in Jcenter

You need to exclude RxJava group from dependency or remove RxJava dependency from gradle.

implementation ('io.hengam.lib:base:1.0.5')  {
    exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
}
Related