Android java.lang.IllegalArgumentException: Invalid Transition types
Asked Answered
B

5

9

Recently i have got java.lang.IllegalArgumentException: Invalid Transition types. This exception happens on android api 19 and it appeared after i have updated android build tools and support libraries to version 27.

Does anyone know what has changed with KitKat transitions?

    Fragment fragment = new  Fragment();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Transition transition = new AutoTransition();
        fragment.setSharedElementEnterTransition(transition);
    }

    String backStateName = fragment.getClass().getName();
    FragmentManager manager = getFragmentManager();
    FragmentTransaction ft = manager.beginTransaction();
    ft.addSharedElement(view, "TransitionView");
    ft.replace(R.id.mainActivity_container, fragment, backStateName);
    ft.addToBackStack(backStateName);
    ft.commit();

Full exception:

Fatal Exception: java.lang.IllegalArgumentException: Invalid Transition types
   at android.support.v4.app.FragmentTransition.chooseImpl(FragmentTransition.java:461)
   at android.support.v4.app.FragmentTransition.configureTransitionsOrdered(FragmentTransition.java:3317)
   at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
   at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
   at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
   at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5590)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
   at dalvik.system.NativeStart.main(NativeStart.java)

UPDATE

After changing from if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) to if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) I don't get exception.

Broadleaf answered 13/4, 2018 at 8:26 Comment(0)
H
19

You are mixing transitions from androidx (the support library) and the platform. For example.:

import androidx.transition.AutoTransition;
import android.transition.Fade;

(note the missing 'x')

Change that to only use support library, like this:

import androidx.transition.AutoTransition;
import androidx.transition.Fade;
Hazlip answered 16/11, 2018 at 15:24 Comment(4)
In my case I was mixing androidx.* transitions with android.* transitionsChaperon
Thanks @AdamJohns. Ive changed the answer to androidxHazlip
Made my day. Thanks! <3Hollie
I'm my case, I was missing "x" on import androidx.transition.TransitionInflaterErnst
W
4

Looking at the change here it looks like it should probably read 'must' use support transitions rather than 'can' use them. Try changing your AutoTransition from android.transition.AutoTransition to android.support.transition.AutoTransition and it should work perfectly without needing any SDK version checks.

Waligore answered 14/5, 2018 at 8:54 Comment(0)
C
3

check your fragment import like below..

import android.support.v4.app.Fragment;

if you used addSharedElement make change in app level gradle file api level 21.

     minSdkVersion 21
Comenius answered 13/4, 2018 at 8:36 Comment(11)
Yes, I'm using correct import and i cant set minSdkVersion to 21 because i need to support my app to lower api devices. Also the same code worked before build tools and support libraries updateBroadleaf
that time you need to define annotation for particular method like @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)Comenius
So what i need to do to make transitions work beginning with api19.Broadleaf
transitions will be work main things addSharedElement is need api 21.Comenius
i have added if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ft.addSharedElement(view, "TransitionView"); but still get the exceptionBroadleaf
you can not show any fragment which transper. like HomeFragment fragment=new HomeFragment.Comenius
This is just abstract code. i have class which extends fragment which i am using.Broadleaf
Okay, i have changed to check from KITKAT to LOLLIPOP before creating the transition and everything is okay. But i dont understand why the same code worked properly with build tools version 26Broadleaf
Can you share you whole log ? you should not face crash if you add following lins (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)Comenius
As per your updated answer you are not getting exception ?Comenius
Yes, as I said, after changing from KITKAT to LOLLIPOP everything is okay. Just curious why it worked with earlier buildsBroadleaf
H
1

After switching to androidX, I got this error because some import was from

android.package

and some from

androidx.package

Hydrozoan answered 22/11, 2018 at 10:26 Comment(0)
M
0

In my case I was using MaterialContainerTransform and I replaced

com.google.android.material.transition.platform 

by

com.google.android.material.transition
Monitorial answered 3/9, 2020 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.