无法将 RxJava 与 Hengam SDK 一起使用

Can't use RxJava with Hengam SDK

我最近在我的项目中添加了 Hengam SDK;但不幸的是我不能再使用 RxJava 并且它会导致重复异常。值得一提的是,在将 SDK 添加到项目之前,一切正常。

这是堆栈跟踪:

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 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)

这是怎么回事?是否与SDK有冲突或需要额外配置才能使用RxJava? 如有任何回应,我们将不胜感激...

您需要从依赖项中排除 RxJava 组或从 gradle 中移除 RxJava 依赖项。

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

AFAIK,Hengam 有一个自定义的 RxJava2(为了保持 SDK 的最终大小)。因此,如果您想将 RxJava2 与 Hengam 一起使用,则需要排除它的自定义 RxJava2 并实现实际的库。

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

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

因此 io.hengam.lib:rxjava 不会导入到 class 路径,而是添加 ReactiveX 的 RxJava2。

:
1. 使用RxJava2 2.2.9 或更高版本。
2. RxJava3 与 RxJava2 相比有不同的封装。所以确保你添加 RxJava2

Hengam reference in Jcenter