Cumbaja
Cumbaja

Reputation: 45

Can I use RxJava2 and RxAndroid in a single java class library?

I'm tasked with creating an SDK that can be consumed from both Android & Java applications using ReactiveX programming. I already have an android project using RxAndroid created, but now I need to extend it with RxJava2.

The question I'm facing is whether I should create 'regular' java class library and use it for both scenarios or create 2 separate packages (which would mean a lot of duplicate code + maintenance).

Is this even possible? And if so, is it a good practice?

Upvotes: 0

Views: 87

Answers (2)

solidak
solidak

Reputation: 5081

As an addition to @AlexeyRomanov's answer, feel free to check out this library which could be used for both Android and Java projects: https://github.com/JakeWharton/RxRelay.

Its basically an extension to RxJava, but it might give you a solid idea where to go. Good luck!

Upvotes: 0

Alexey Romanov
Alexey Romanov

Reputation: 170745

whether I should create 'regular' java class library and use it for both scenarios

Yes. What I would do to start is simply change your Android library project to be a standard Java library and replace RxAndroid dependency by RxJava. Most code should still compile. Code which doesn't will mostly use schedulers provided by RxAndroid and can be changed to take Scheduler parameters.

Then create an Android Library project which depends on the Java Library and put the RxAndroid-specific code there.

Upvotes: 1

Related Questions