skip to Main Content

In my latest release, I suddenly started getting this error: Resources$NotFoundException: Resource ID #0x7f080120. The resource ID is my notification icon, which is used in one of the tabs in a ViewPager, which is displayed at startup. I am not able to reproduce the issue myself, but see a lot of new crashes in Firebase Crashlytics.

The notification icon is stored in multiple densities: enter image description here

The code that causes the crash:

ContextCompat.getDrawable(context, R.drawable.ic_notification_icon)

The weird thing is that I did not change anything related to this drawable or the code in the ViewPager in this release. The best suggestion I found from searching around, was to clean and rebuild the project. I did this and uploaded a new version, but the crash reappeared.

The crash is observed on the following Android versions:

  • Android 13
  • Android 11
  • Android 8.1.0
  • Android 7.1.2

And the following devices:

  • Galaxy A53 5G
  • Nexus 5X
  • Standard PC (i440FX + PIIX, 1996)
  • vivo S1
  • OnePlus8Pro
  • Mi 9x

Edit:
I can see that 44% of the affected devices are rooted. Does it mean I should not worry about the issue?

2

Answers


  1. ContextCompat is creating the issue

    use it directly

    getDrawable(context, R.drawable.ic_notification_icon)

    Login or Signup to reply.
  2. We are too facing this kinda of error a lot in our app. So,By doing little bit of search, I am changing ContextCompat to AppCompatResources to get the drawables. I seriously don’t know now yet it will be beneficial for our app or not but reason to change is simply because the way ContextCompat returns result with respect to the way the AppCompatResources returns result. ContextCompat is just calling context’s getDrawable method which in turn calls Resource’s getDrawable method which in turn calls ResourceImpl getValueForDensity method and finally calling a native method. Whereas AppCompatResources calls AppCompatDrawableManager‘s getDrawable method which try different approaches to get the drawable and eventually fallback to ContextCompat if none of the approaches work. This seems to be better candidate for me get the drawable.

    AppCompatDrawableManager’s getDrawable method

    public Drawable getDrawable(@NonNull Context context, @DrawableRes int resId,
            boolean failIfNotKnown) {
        checkVectorDrawableSetup(context);
        Drawable drawable = loadDrawableFromDelegates(context, resId);
        if (drawable == null) {
            drawable = createDrawableIfNeeded(context, resId);
        }
        if (drawable == null) {
            drawable = ContextCompat.getDrawable(context, resId);
        }
        if (drawable != null) {
            // Tint it if needed
            drawable = tintDrawable(context, resId, failIfNotKnown, drawable);
        }
        if (drawable != null) {
            // See if we need to 'fix' the drawable
            DrawableUtils.fixDrawable(drawable);
        }
        return drawable;
    }
    

    This answer also has useful information too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search