trello-archive/RxLifecycle

androidx support

Closed this issue · 9 comments

I'm an early androidx adopter and RxLifecycle doesn't work with it, even when enabling the jettifier and androidx support:

android.useAndroidX=true
android.enableJetifier=true

when I try to bindToLifecycle I obtain an error like:

Required: LifecycleOwner
Found: Fragment

Of course the Fragment is an androidx Fragment and it IS a LifecycleOwner.

But the LifecycleOwner RXLifecycle expect is android.arch.lifecycle.LifecycleOwner while the androidx LifecycleOwner is androidx.lifecycle.LifecycleOwner.

dlew commented

Could you provide a bit more of a stack trace? I haven't actually tried this out myself yet.

Now bindToLifeCycle except android.arch.lifecycle.LifecycleOwner
Should be update to except androidx.lifecycle.LifecycleOwner

public fun <T> io.reactivex.Single<T>.bindToLifecycle(owner: android.arch.lifecycle.LifecycleOwner): io.reactivex.Single<T> { /* compiled code */ }

@dlew sorry forgot to answer. It's basically what @RubyLichtenstein said. They simply changed the package of LifecycleOwner and RxLifecycle still look in the other one.

I wrote a simple class like the one Ruby share to keep going for my project.

jcsla commented

@dlew
Please merge this PR to another branch. Thanks.

dlew commented

It's still not exactly clear to me why the Jetifier doesn't work here, since the point of it is to change android.arch.* to androidx.*. If it's not doing that, then we should be filing bugs with the Jetifier, not trying to change this lib. Changing this lib would cause problems for anyone who isn't updated to AndroidX yet.

At the very least, what we'd need to do is support is to create another artifact, not modify the existing ones (since that'd break back-compat).

dlew commented

Here's what I've decided to do for now: I'm updating all the dependencies (since referencing android arch 1.0.0 instead of 1.1.0 was causing problems for R8). If, after that update, AND after Jetifier is stable, people are still having Jetifier issues, then we can look into a longer-term solution.

However, what I explicitly do not want to do is just update the package names in the library. That will break everyone who isn't switching to AndroidX just yet, which is completely fair given that it's only in beta.

Jetifier works fine.
You just need to add following extensions for kotlin:
RxLifecycleKtx for androidX

I'm just invalidate caches / restart and it worked :D