1

I have 5 crashes in Crashlytics. 2x in Resources.java and 3x in ResourcesImpl:

  • 5 events 2 users Resources.java line 1266 - Android 5.1
  • 5 events 1 user ResourcesImpl.java line 215 - Android 8.1.0
  • 4 events 1 user Resources.java line 1351 - Android 6.0.1
  • 2 events 1 user ResourcesImpl.java line 195 - Android 8.0.0
  • 2 events 2 users ResourcesImpl.java line 190 - Android 7.1.1

enter image description here enter image description here

I cannot see where it goes wrong in the code, given Resources.java is an Android SDK file. I do have a couple of places where Resources is being called:

someText = getContext().getResources().getString(R.string.debug_loading);
bitmap = BitmapFactory.decodeResource(applicationContext.resources, R.mipmap.ic_launcher)

And I've added everywhere this is being called below code:

    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
    } catch (Resources.NotFoundException e) {
        e.printStackTrace();
    }

Is this the right approach since we cannot reverse engineer the Resource ID and thus don't know where exactly the problem is happening?

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

3 Answers3

2

Can you confirm if this belongs to only Android OS 5 and 5.1, if yes then it seems to be a bug with androidx.appcompat 1.1.0 Ref: - https://issuetracker.google.com/issues/141132133

Try downgrading to androidx.appcompat:appcompat:1.0.2 once if it gets resolved

Dishant Walia
  • 701
  • 5
  • 8
  • I think your solution solves 1 of the 4 crashes. And the other 4 issues are a different problem. – Jim Clermonts Dec 23 '19 at 09:44
  • If this crashes occur on release build with android app bundle try to disable split configuration on density basis. `bundle { density{ enableSplit = true }}` – Dishant Walia Jan 07 '20 at 11:35
1

If you're not using app bundles (.aab), disregard all of this.

If you are, this is caused by users sideloading your app. For example, if a user on a low end device downloads an APK intended for a high end device, they will be unable to access the correct resources. Crash!

This can be fixed by manually checking the installer package on first run / startup. This isn't 100% reliable.

Note: There was previously an excellent library by Google to check all necessary parts of the app exist, and display an install prompt if not. This seems to have disappeared entirely besides basic documentation, will keep on trying to find out what happened to it.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
0

I can't tell you exactly why this happens, but I can help you to find out.

Your error comes from the Material components library. The test_custom_background drawable can't be located in those devices for some reason. Check if you are using that directly, and provide an alternative. If not, possible causes for that kind of error are:

-SDK level conflicts: Check the SDK level of the afflicted devices. Google tends to screw up theming for lower/newer SDKs.

-Removal of a SDK level resource from the device vendor: Sometimes vendors (hello, samsung!) modify the SDK for their convenience and in the process, they delete/change low level stuff/resources you need.

-Sideloading an app bundle.

For future reference, the ResourcesNotFoundException resource ID is a String composed of "0x" plus the conversion of the ID to an unsigned hexadecimal on base 16:

void getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs)
            throws NotFoundException {
        boolean found = mAssets.getResourceValue(id, 0, outValue, resolveRefs);
        if (found) {
            return;
        }
        throw new NotFoundException("Resource ID #0x" + Integer.toHexString(id));
    }

So, when facing this kind of error, just reverse the code and look for the ID:

Log.d("stackoverflow", "id is "+Integer.parseUnsignedInt("7f07008d", 16))

This gives us 2131165325, which, if searched in the android developers website, gives us :

test_custom_background
int test_custom_background
Constant Value: 2131165325 (0x7f07008d)

from com.google.android.material.R.drawable : https://developer.android.com/reference/com/google/android/material/R.drawable

I hope this helps you to find the root cause. happy hunting, and happy holidays!

Fco P.
  • 2,486
  • 17
  • 20
  • I don't have any test_custom_background reference in my code. Maybe in a library, I'll try. Thanks for this information! – Jim Clermonts Jan 03 '20 at 10:56
  • Try checking the app's dependencies tree (./gradlew app:dependencies) to see which dependency is pulling this is in, and from there you can start looking for the solution to the three remaining crashes. Good luck! – Fco P. Jan 03 '20 at 21:38
  • ./gradlew app:dependencies gives me a long list of library names, this is not useful I think? Searching for 2131165325 on google indeed just returns test_custom_background. – Jim Clermonts Jan 06 '20 at 08:08