Marcin Kunert Marcin Kunert - 14 days ago 5x
Android Question

Expected resource of type animator [ResourceType]

I've updated my SDK to the newest version, but now I am getting a lint error.

Error: Expected resource of type animator [ResourceType]

The error occurs on this line:

AnimatorInflater.loadAnimator(context, R.anim.right_slide_in)

The referenced resource
looks like this:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android=""
android:duration="450" />

It always worked before. Could somebody explain why I am getting that error?


The error occurs because you store your Animator resources in the wrong directory! It worked before because the AnimatorInflater can load the xml regardless of in which folder it is saved.

  • R.anim.* resources from the res/anim/ folder are for view animations.
  • R.animator.* resources from the /res/animator/ folder are for Animators.

So to fix the error just move your Animator resources from /res/anim/ to /res/animator/.

This used to make no difference at all until the resource type annotations were added to the support library. A long with those annotations there also were many new lint checks among others the one which tripped you up.

In the future if you get an error like this you can look at the annotation to figure out what you are doing wrong. For example the implementation of loadAnimator() of the AnimatorInflater looks like this:

public static Animator loadAnimator(Context context, @AnimatorRes int id)
        throws NotFoundException {
    return loadAnimator(context.getResources(), context.getTheme(), id);

The @AnimatorRes annotation on the id parameter indicates that only Animator resources should be passed here. If you look at the documentation of @AnimatorRes it reads like this:

Denotes that an integer parameter, field or method return value is expected to be an animator resource reference (e.g. android.R.animator.fade_in).

If the description doesn't explain the error already, then the example usually does ;)