profound_swami
profound_swami

Reputation: 133

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/graphics/BlendModeColorFilter;

This app crashes when I am running it on the emulator. The line that causes it to crash is v.getBackground().setColorFilter.

But, there is no problem when testing the app on an actual device.

button.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                v.getBackground().setColorFilter(new BlendModeColorFilter(0xe0f47521, BlendMode.SRC_ATOP));
                v.invalidate();
                break;
            }
            case MotionEvent.ACTION_UP: {
                v.getBackground().clearColorFilter();
                v.invalidate();
                break;
            }
        }
        return false;
    }
});

Upvotes: 1

Views: 1104

Answers (1)

r4dixx
r4dixx

Reputation: 81

As mentionned previously, BlendModeColorFilter wasn't introduced until API level 29. An error should be thrown at build time if you ask me but I digress...

The best solution in my opinion is to go with BlendModeColorFilterCompat available in recent androidx core releases as described here.

Which would give:

v.getBackground().setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(-0x1f0b8adf, BlendModeCompat.SRC_ATOP));

Upvotes: 3

Related Questions