You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android API19升级构建工具至27后出现Invalid Transition types异常求助

Fixing java.lang.IllegalArgumentException: Invalid Transition types on KitKat (API 19)

Hey there, I’ve run into a similar snag after upgrading support libraries, so let’s break down what’s going on here.

Why this exception pops up

After upgrading your build tools and support libraries to version 27, you’re hitting a validation check that was either loose or unenforced in older library versions. The core issue is:

  • AutoTransition is a composite transition (it bundles Fade, ChangeBounds, and ChangeTransform by default) built for general fragment enter/exit animations.
  • On KitKat (API 19), the Shared Element Transition system is extremely limited—it doesn’t support composite transitions like AutoTransition. Only single, shared-element-compatible transition types (like ChangeBounds, ChangeTransform, or ChangeImageTransform) are allowed here.

Key KitKat Transition Changes to Know

Android 4.4 was the first release to introduce Shared Element Transitions, but it was a very basic implementation:

  • Only a tiny subset of transition types work for shared elements (no composite transitions, no complex animations like Explode or Slide for shared elements).
  • The transition framework was still in its early stages, so many smooth behaviors from API 21+ don’t translate to KitKat.
  • Later support library versions (like 27+) tightened up validation for these older APIs, which is why you’re seeing this exception now when you didn’t before.

The Solution

Replace the AutoTransition with a single, shared-element-compatible transition. For most use cases, ChangeBounds is the safest pick—it handles resizing and moving shared elements, which is the most common shared element scenario:

Fragment fragment = new Fragment();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    // Swap AutoTransition for a shared-element-friendly single transition
    Transition transition = new ChangeBounds();
    fragment.setSharedElementEnterTransition(transition);
}
String backStateName = ...

If you need an effect similar to AutoTransition, you can try combining supported transitions manually (just note KitKat’s transition system can be finicky with combinations):

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    TransitionSet transitionSet = new TransitionSet();
    transitionSet.addTransition(new ChangeBounds());
    transitionSet.addTransition(new Fade()); // Fade works for non-shared elements, test carefully
    fragment.setSharedElementEnterTransition(transitionSet);
}

Alternatively, if shared element transitions aren’t critical for KitKat users, you can restrict complex transitions to API 21+ only:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Use AutoTransition or other complex transitions only on newer devices
    Transition transition = new AutoTransition();
    fragment.setSharedElementEnterTransition(transition);
}

内容的提问来源于stack exchange,提问作者Martynas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:26:51