这是indexloc提供的服务,不要输入任何密码
Skip to content

4.16.0, SDK 35, log spam "BitmapDrawable created with null Bitmap" #5550

@nikclayton

Description

@nikclayton

I'm updating my app to SDK 35 per the Google Play requirements -- https://support.google.com/googleplay/android-developer/answer/11926878?hl=en

I've noticed the logs are now being spammed by

BitmapDrawable created with null Bitmap

That's in the Android sources for BitmapDrawable.java in two functions next to each other:

    @Deprecated
    public BitmapDrawable(Bitmap bitmap) {
        if (bitmap == null) {
            Log.w(TAG, "BitmapDrawable created with null Bitmap");
        }
        init(new BitmapState(bitmap), null);
    }

    /**
     * Create drawable from a bitmap, setting initial target density based on
     * the display metrics of the resources.
     */
    public BitmapDrawable(Resources res, Bitmap bitmap) {
        if (bitmap == null) {
            Log.w(TAG, "BitmapDrawable created with null Bitmap");
        }
        init(new BitmapState(bitmap), res);
    }

Putting a breakpoint on those log lines and walking up the stack trace the culprit is in Glide's ImageViewTarget.java, specifically:

  public void onLoadStarted(@Nullable Drawable placeholder) {
    super.onLoadStarted(placeholder);
    setResourceInternal(null);
    setDrawable(placeholder);
  }

That setResourceInternal(null); line eventually results in the call to BitmapDrawable (the deprecated version), hence the log.

The full stack trace is:

<init>:154, BitmapDrawable (android.graphics.drawable)
setImageBitmap:764, ImageView (android.widget)
setImageBitmap:124, AppCompatImageView (androidx.appcompat.widget)
setResource:35, BitmapImageViewTarget (com.bumptech.glide.request.target)
setResource:10, BitmapImageViewTarget (com.bumptech.glide.request.target)
setResourceInternal:126, ImageViewTarget (com.bumptech.glide.request.target)
onLoadStarted:67, ImageViewTarget (com.bumptech.glide.request.target)
begin:263, SingleRequest (com.bumptech.glide.request)
runRequest:41, RequestTracker (com.bumptech.glide.manager)
track:688, RequestManager (com.bumptech.glide)
into:858, RequestBuilder (com.bumptech.glide)
into:917, RequestBuilder (com.bumptech.glide)
set:1325, MainDrawerImageLoader (app.pachli)
...

In my code the line 1325 call site looks like this:

  1320:     override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
  1321:         val glide = Glide.with(imageView)
  1322:         if (animateAvatars) {
  1323:             glide.load(uri).placeholder(placeholder).into(imageView)
  1324:         } else {
* 1325:             glide.asBitmap().load(uri).placeholder(placeholder).into(imageView)
  1326:         }
  1327:     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions