Crashlytics 在应用程序启动时因 Resources$NotFoundException 而崩溃

Crashlytics crashing with Resources$NotFoundException on app launch

我最近检查了我的 google 播放崩溃,发现我有成千上万的用户遇到了这个崩溃,但 crashlytics 上没有任何内容:

java.lang.RuntimeException: 
  at android.app.ActivityThread.installProvider (ActivityThread.java:7110)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:6594)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6498)
  at android.app.ActivityThread.-wrap2 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1963)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7425)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.ResourcesImpl.getResourcePackageName (ResourcesImpl.java:325)
  at android.content.res.Resources.getResourcePackageName (Resources.java:2099)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcePackageName (CommonUtils.java:768)
  at io.fabric.sdk.android.services.common.CommonUtils.getResourcesIdentifier (CommonUtils.java:518)
  at io.fabric.sdk.android.services.common.CommonUtils.getBooleanResourceValue (CommonUtils.java:499)
  at io.fabric.sdk.android.services.common.FirebaseInfo.isFirebaseCrashlyticsEnabled (FirebaseInfo.java:56)
  at com.crashlytics.android.CrashlyticsInitProvider.shouldInitializeFabric (CrashlyticsInitProvider.java:85)
  at com.crashlytics.android.CrashlyticsInitProvider.onCreate (CrashlyticsInitProvider.java:25)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1919)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1894)
  at android.app.ActivityThread.installProvider (ActivityThread.java:7107)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:6594)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6498)
  at android.app.ActivityThread.-wrap2 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1963)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7425)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

Whosebug 上的类似问题: Question 1 Question 2

我有一个正在进行的支持 Fabric 的电子邮件线程,但他们认为发生这种情况的唯一原因是因为:

2018-12-09 14:39:09.899 [DEBUG] (Thread-6) com.crashlytics - Crashlytics found ProjectName, a module missing required artifacts: Root: E:\DevelopmentEnvironment\Projects\ProjectName(Exists), Manifest: E:\DevelopmentEnvironment\Projects\ProjectName\AndroidManifest.xml (Doesn't Exist), Res: E:\DevelopmentEnvironment\Projects\ProjectName\res (Doesn't Exist), Assets: E:\DevelopmentEnvironment\Projects\ProjectName\assets (Doesn't Exist), Data: C:\Users\hvkro_000.crashlytics\com.crashlytics.tools\ProjectName-bec53d32b3aec63f870c6dd19f7186ae46e1e3a1 (Doesn't Exist), NDK_OUT: null (Doesn't Exist), NDK_LIBS_OUT: null (Doesn't Exist) , (Maven? false), (Gradle false), (Using any IML? true), (Using any Default? true) (Manifest-Found-In: root? false src/main? false) (Res-Found-In: root? false src/main? false) (Assets-Found-In: root? false src/main? false)

We can't find your manifest. I believe this is the problem.

我无法在我这边重现这个问题,但正如您在下面看到的,相当多的用户正在发生这个问题。 我已经研究了很长时间,但我无法弄清楚是什么导致了这个问题。 任何帮助将不胜感激。

稍作改动后,我解决了这个问题。 以前我是这样初始化 Fabric 的:

Fabric.with(this, new Crashlytics.Builder().core(crashlyticsCore).build());

然后我将其更新为如下所示:

final Crashlytics crashlytics = new Crashlytics.Builder().core(crashlyticsCore).build();
    final Fabric fabric = new Fabric.Builder(this)
            .kits(crashlytics)
            .debuggable(BuildConfig.DEBUG)
            .build();
    Fabric.with(fabric);

此更改解决了我的问题。 但是 fabric 团队应该比我先发现它,因为我已经与他们分享了我是如何初始化 fabric 的。之前的代码是 fabric 在他们的文档中如何被初始化的。他们至少应该反对这种初始化方式。

For me it happened after I moved to app bundle.

我无法重现它,但在分析 Crashlytics 日志历史后,我意识到它是在我移动到应用程序包后开始发生的。所以我回到了 apk,现在我不再遇到这些问题了。