Search code examples
javaandroidandroid-drawableandroid-resourcesandroid-tablayout

Resources$NotFoundException on some devices (setIcon)


On Google Play store, I can see below crash log output on certain devices (Android 8.0 and 8.1). However, I'm unable to figure out the reason as a potentially missing resource ID is missing in the log output and in all drawable folders (hdpi, mdpi, xhdpi, xxhdpi, xxxhdpi), I've the necessary PNG-images.

Do you have an idea what the reason could be?

Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.ResourcesImpl.getValue (ResourcesImpl.java:215)
  at android.content.res.Resources.getValue (Resources.java:1316)
  at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded (ResourceManagerInternal.java:176)
  at androidx.appcompat.widget.ResourceManagerInternal.getDrawable (ResourceManagerInternal.java:141)
  at androidx.appcompat.widget.ResourceManagerInternal.getDrawable (ResourceManagerInternal.java:132)
  at androidx.appcompat.content.res.AppCompatResources.getDrawable (AppCompatResources.java:104)
  at com.google.android.material.tabs.TabLayout$Tab.setIcon (TabLayout.java:1968)
  at com.xyz.myapp.MainActivity.setupTabIcons (MainActivity.java:184)
  at com.xyz.myapp.MainActivity.initialize (MainActivity.java:176)
  at com.xyz.myapp.MainActivity.onRequestPermissionsResult (MainActivity.java:453)
  at android.app.Activity.dispatchRequestPermissionsResult (Activity.java:7429)
  at android.app.Activity.dispatchActivityResult (Activity.java:7280)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4264)

Solution

  • I started getting a few of these reports after switching to app bundles. I always assumed they were from users who downloaded my apps from third-party APK mirror sites. So if the APK they downloaded doesn't match their device's density bucket, the app crashes as the relevant assets just aren't there.