Mark
Mark

Reputation: 7718

"androidx.transition.TransitionSet cannot be cast to android.transition.Transition" after updating androidx lifecycle from 2.2.0-alpha03 to alpha04

There are a few other questions like this but all refer to Android Support library. I'm using the new androidx libraries instead.

After updating the androidx lifecycle dependency from 2.2.0-alpha03 to 2.2.0-alpha04, I get the following crash (on Android 9):

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp, PID: 12345
    java.lang.ClassCastException: androidx.transition.TransitionSet cannot be cast to android.transition.Transition
        at androidx.fragment.app.FragmentTransition.setListenerForTransitionEnd(FragmentTransition.java:307)
        at androidx.fragment.app.FragmentTransition.configureTransitionsOrdered(FragmentTransition.java:419)
        at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:139)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2383)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2341)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2244)
        at androidx.fragment.app.FragmentManager$3.run(FragmentManager.java:422)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

Same problem with version 2.2.0-alpha05.

UPDATE: actually, it seems that androidx fragment 1.2.0-alpha03 is being pulled in, and that is causing the problem. When using fragment 1.2.0-alpha02, the crash does not occur. The problematic cast is added here:

https://android.googlesource.com/platform/frameworks/support/+/1b07d07c5a5ca70bdddeab356e7f5175f60094d4%5E%21/#F4

This crash happens after calling:

supportFragmentManager
    .beginTransaction()
    .remove(f)
    .commit()

And the only workaround I've found is to remove the exit transition:

f.exitTransition = Slide(gravity)

Note, the fragment f is of type: androidx.fragment.app.Fragment

Any ideas?

Upvotes: 2

Views: 955

Answers (2)

Sam_Fani
Sam_Fani

Reputation: 11

I had same problem running gradle implementation "androidx.fragment:fragment-ktx:1.2.5" and none of the above solutions worked for me However, when I upgraded to 1.3.0-rc01 the issue disappeared

Upvotes: 0

jeremybwoods
jeremybwoods

Reputation: 26

This issue has been fixed in the upcoming Fragment 1.2.0-beta01 release.

See the bug here: https://issuetracker.google.com/issues/142056487

Upvotes: 1

Related Questions