daimajia/AndroidViewAnimations · critical · Error
Can not init animatorClazz instance
Error message
Can not init animatorClazz instance
What it means
YoYo's Techniques enum entries each point to a Class object (animatorClazz) of a BaseViewAnimator subclass. getAnimator() reflectively instantiates it with Class.newInstance(); this Error is a catch-all rethrow of any failure during that reflective instantiation (no public no-arg constructor, wrong visibility, or an exception in the class's <clinit> or constructor). It is thrown as a hard java.lang.Error, not a RuntimeException, because at that point the library assumes its internal animation classes are well-formed.
Solutions
- Do not obfuscate library animation classes: add ProGuard/R8 keep rules like -keep class com.daimajia.androidanimations.library.** { *; }
- If you registered a custom Technique, make its animator class public with an explicit public no-arg constructor
- Sync/upgrade the library version so animator classes match the Techniques enum entries (clean resolution: ./gradlew --refresh-dependencies)
- Catch the Error at the call site and fall back to a safe animation (e.g. Techniques.FadeIn) or no animation
- Reproduce with the reflective call wrapped in try/catch to log the original Exception 'e' — this error discards the root cause
Example fix
// before
public class MyAnimator extends BaseViewAnimator {
private MyAnimator() {} // private ctor -> newInstance() fails
}
// after
public class MyAnimator extends BaseViewAnimator {
public MyAnimator() {} // public no-arg ctor, required for reflection
} Defensive patterns
Strategy: try-catch
Validate before calling
// Sanity-check that the animator is reflectively instantiable before composing:
try {
Object o = Techniques.FadeIn.getClass();
// If you hold the animator Class yourself, verify:
// Class<?> c = MyAnimator.class;
// c.getDeclaredConstructor(); // throws if no no-arg ctor
} catch (Throwable t) {
android.util.Log.w("YoYo", "Animator not instantiable", t);
} Type guard
// Java: verify the class hierarchy and modifiers before trusting a Technique's animator
static boolean isValidAnimator(Class<?> clazz) {
return clazz != null
&& BaseViewAnimator.class.isAssignableFrom(clazz)
&& java.lang.reflect.Modifier.isPublic(clazz.getModifiers())
&& !java.lang.reflect.Modifier.isAbstract(clazz.getModifiers());
} Try / catch
try {
YoYo.with(Techniques.Bounce).duration(700).playOn(view);
} catch (Error e) { // getAnimator throws java.lang.Error
Log.w("YoYo", "animation failed to init, skipping", e);
// optional fallback:
// YoYo.with(Techniques.FadeIn).duration(300).playOn(view);
} Prevention
- Add keep rules for com.daimajia.androidanimations.library.** in ProGuard/R8 configs
- Never use animator classes with private or absent no-arg constructors
- Test animations in a minified release build, not only debug, before shipping
- Prefer built-in Techniques enum entries over hand-crafted custom ones
- Keep the library version consistent across modules to avoid enum/class drift
When it happens
Trigger: Calling YoYo.with(Techniques.X) and letting it call getAnimator() when the resolved animator class cannot be reflectively instantiated: (1) the class has no public no-arg constructor, (2) the class is non-public/abstract or its constructor throws during animation setup, (3) the Class object does not actually extend BaseViewAnimator so the cast fails, (4) instantiation fails due to class-initializer errors (e.g. missing/renamed resources under a shrunk package).
Common situations: ProGuard/R8 obfuscation stripping or renaming animator subclasses so newInstance() fails at runtime; a forked/custom Technique added without a public no-arg constructor; library version changes that removed or renamed animator classes; animator static initialization throwing in certain device/theme environments.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of daimajia/AndroidViewAnimations@6a35c466d2 (2026-09-08).
Data as JSON: /api/errors/16d450c2ecc4d249.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/daimajia/androidanimations/library/Techniques.java:181
ZoomOut(ZoomOutAnimator.class),
ZoomOutDown(ZoomOutDownAnimator.class),
ZoomOutLeft(ZoomOutLeftAnimator.class),
ZoomOutRight(ZoomOutRightAnimator.class),
ZoomOutUp(ZoomOutUpAnimator.class);
private Class animatorClazz;
private Techniques(Class clazz) {
animatorClazz = clazz;
}
public BaseViewAnimator getAnimator() {
try {
return (BaseViewAnimator) animatorClazz.newInstance();
} catch (Exception e) {
throw new Error("Can not init animatorClazz instance");
}
}
}
View on GitHub (pinned to 6a35c466d2)