Android O: DragShadowBuilder throws IllegalStateException: Software rendering doesn't support hardware bitmaps

My Android app allows users to drag and drop images in an activity. It used to work fine until Android O and hardware image acceleration arrived. The code throws the following exception now:

IllegalStateException: Software rendering doesn't support hardware bitmaps

Here is my code:

public class PhotoDragShadowBuilder extends DragShadowBuilder {
    @Override
    public void onDrawShadow(Canvas canvas) {
        Drawable photoDrawable = imageView.getDrawable();
        photoDrawable.draw(canvas);
    }
}

The Bitmap inside of imageView.getDrawable() has the flag Bitmap.Config.HARDWARE set. It means that the bitmap is only stored in hardware. Android refuses to draw the Bitmap to the canvas that's stored in heap.

The responsible Android source code for the exception is here: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/graphics/java/android/graphics/BaseCanvas.java#532

Obviously, I could load the Bitmap a second time for dragging and dropping. However, that's extra work for the device plus requires tying together a lot of nicely decoupled code.

Is there a way to fix this? Is there a way to get the Bitmap out of the hardware and into heap?

This Glide issue on the Glide web site explains what's going on: https://github.com/bumptech/glide/issues/2309

The solution is to disable hardware acceleration in Glide: http://bumptech.github.io/glide/javadocs/431/com/bumptech/glide/request/RequestOptions.html#disallowHardwareConfig--

Disables the use of Bitmap.Config.HARDWARE in Downsampler to avoid errors caused by [...] drawing to Canvass backed by Bitmaps

The code below shows how to disable hardware acceleration for the specific image.

            GlideApp.with(context)
                .applyDefaultRequestOptions(new RequestOptions().disallowHardwareConfig())
                .load(imageUrl)
                .into(imageView);

Android O: DragShadowBuilder throws IllegalStateException , Android O: DragShadowBuilder throws IllegalStateException: Software rendering doesn't support hardware bitmaps - android. Pixels with resulting OpenGL alpha values less than 1.0 will be overlaid on any underlying Swing rendering. This component attempts to use hardware-accelerated rendering via FBO or pbuffers and falls back on to software rendering if none of the former are available using GLDrawableFactory.createOffscreenDrawable(..).

Workaround for ANDROID O causes an error"IllegalStateException: Software rendering doesn't support hardware bitmaps".

Recode your public class GlideConfiguration extends AppGlideModule as below:

    RequestOptions options = new RequestOptions();
    boolean isAndroidO = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O);
    DecodeFormat format = isAndroidO ? DecodeFormat.PREFER_ARGB_8888 : DecodeFormat.PREFER_RGB_565;
    options.format(format);
    if (isAndroidO) options.disallowHardwareConfig();

    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
    builder.setDefaultRequestOptions(options);

java.lang.IllegalStateException: Software rendering doesn't support , Stetho will makes app crash at sometime.This is the crash log.Android version is 8.1.0. Fatal Exception: java.lang.IllegalStateException:  * Restore the current matrix when restore () is called. * Restore the current clip when restore () is called. * The layer requires a per-pixel alpha channel. * The layer requires full 8-bit precision for each color channel. * Clip drawing to the bounds of the offscreen layer, omit at your own peril.

Disclaimer:- I didn't use glide in this activity still I was getting "IllegalStateException: Software rendering doesn't support hardware bitmaps"

I solved this error by creating a new activity and copy the code block while also checking does my app run after adding code.

finally, my app is running without any error and I didn't get why this error was thrown.

Software rendering doesn't support hardware bitmaps · Issue #615 , Prior to O, auto-focusable didn't exist and views marked as clickable weren't implicitly rendering. For software-rendered snapshots of a small part of the View {@link #startDragAndDrop(ClipData, DragShadowBuilder, Object, int)} is called throw new IllegalStateException("The android:onClick attribute cannot ". [JDK-8098132] - [Android, Ensemble8] App should react to hardware buttons on Android [JDK-8098141] - [Android] Add option to build to use retrolambda to remove lambdas [JDK-8098149] - [Monocle] Use hardware double-buffering in software rendering [JDK-8098151] - Add @font-face to CSS documentation

core/java/android/view/View.java - platform/frameworks/base, startDragAndDrop(ClipData, DragShadowBuilder, Object, int): boolean static boolean sCascadedDragDrop; /** * Prior to O, auto-focusable didn't exist For software-rendered snapshots of a small part of the View hierarchy or isRestricted()) { throw new IllegalStateException("The android:onClick attribute cannot " + "be  This class was deprecated in API level 17. This class is not supported anymore. It is recommended you base your own implementation on the source code for the Android Open Source Project if you must use it in your application. A view that displays one child at a time and lets the user pick among them.

android/android-9.0.0_r35 : android/view/View.java, Android O: DragShadowBuilder throws IllegalStateException: Software rendering doesn't support hardware bitmaps. [ad_1]. My Android app  Drawing is handled by walking the tree and rendering each view that intersects the invalid region. Because the tree is traversed in-order, this means that parents will draw before (i.e., behind) their children, with siblings drawn in the order they appear in the tree.

DragShadowBuilder throws , DragShadowBuilder · View. Constant Value: "android.software.​activities_on_secondary_displays" for virtual reality (VR) applications that handles stereoscopic rendering of notifications, An application must target Android O or higher and declare permission Throws. SecurityException, if the caller does not have the  Added a command line option, -use-host-vulkan, to use software rendering for when the guest uses GLES via Swiftshader, but force hardware (host GPU) rendering for when the guest uses Vulkan. Added support for passthrough graphics via virtio-gpu (This will also require a system image update).