Android Fabric Crashlytics crashing with Resource

2019-03-28 06:31发布

问题:

I've got this report from the google play console - it looks like Fabric is crashing at startup because of a resource not found exception for some users:

java.lang.RuntimeException: 
  at android.app.ActivityThread.installProvider (ActivityThread.java:6423)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:6012)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:5951)
  at android.app.ActivityThread.-wrap3 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1710)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1496)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)

Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.ResourcesImpl.getResourcePackageName (ResourcesImpl.java:248)
  at android.content.res.Resources.getResourcePackageName (Resources.java:2785)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcePackageName (Unknown Source)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcesIdentifier (Unknown Source)
  at io.fabric.sdk.android.services.common.CommonUtils.getBooleanResourceValue (Unknown Source)
  at io.fabric.sdk.android.services.common.FirebaseInfo.isFirebaseCrashlyticsEnabled (Unknown Source)
  at com.crashlytics.android.CrashlyticsInitProvider.shouldInitializeFabric (Unknown Source)
  at com.crashlytics.android.CrashlyticsInitProvider.onCreate (Unknown Source)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1759)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1734)
  at android.app.ActivityThread.installProvider (ActivityThread.java:6420)

Digging into the Crashlytics code it looks like it's crashing on the following function:

public static String getResourcePackageName(Context context) {
    int iconId = context.getApplicationContext().getApplicationInfo().icon;
    return iconId > 0?context.getResources().getResourcePackageName(iconId):context.getPackageName();
}

Can't see why that would happen, though.