Could not find RippleDrawable

Robby Smet picture Robby Smet · Jul 17, 2015 · Viewed 42.2k times · Source

I want to create a ripple dynamically in code.

Code:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      buyButton.setBackground(getPressedColorRippleDrawable(primaryColor, darkerVariant));
}

public static RippleDrawable getPressedColorRippleDrawable(int color, int darkerVariant) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ColorStateList colorStateList = new ColorStateList(
                new int[][]
                        {new int[]{}},
                new int[]
                        {darkerVariant}
        );
        return new RippleDrawable(colorStateList, new ColorDrawable(color), null);
    }
    return null;
}

This works on Lollipop but makes the app crash on my GNEX (4.3).
Error:

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method fragments.ProductDetailFragment.getPressedColorRippleDrawable

07-17 12:57:45.757 30992-30992/com.comizzo.ginsonline E/AndroidRuntime﹕ FATAL EXCEPTION: main

java.lang.VerifyError: fragments/ProductDetailFragment

But RippleDrawable is never used on Gnex because code isn't executed.

How can I fix this ?

Answer

WindsurferOak picture WindsurferOak · Mar 10, 2016

The issue is that you need to return a Drawable instead of a RippleDrawable in getPressedColorRippleDrawable. Otherwise, on pre-lollipop devices, you will get a VerifyError.