android.graphics.drawable.AdaptiveIconDrawable cannot be cast to android.graphics.drawable.BitmapDrawable error

僤鯓⒐⒋嵵緔 提交于 2019-12-04 11:17:29

It appears you're using App Theme Engine, which tries to use you app icon as a bitmap. But since Android 8.0 you can set an adaptive icon, which is not a bitmap, thus the App Theme Engine crashes on it.

This issue has been reported here, but it's not been fixed yet (and probably won't, since it hasn't seen any updates for two years).

You might be able so fix this yourself by forking the project and changing the problematic part to not require a bitmap icon. Or alternatively, use another theme engine.

In ATE.java file, implement this

@NonNull
static private Bitmap getBitmapFromDrawable(@NonNull Drawable drawable) {
    final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bmp);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bmp;
}

And change

if (icon == null)
        icon = ((BitmapDrawable) activity.getApplicationInfo().loadIcon(activity.getPackageManager())).getBitmap();

to

if (icon == null)
        icon = getBitmapFromDrawable(activity.getApplicationInfo().loadIcon(activity.getPackageManager()));
Gowtham

I am also facing same error. It's due to ic_launcher creating automatically AdaptiveIcon. I just remove adaptive icon(ic_launcher.xml) and run, so it's working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!