java.lang.RuntimeException:无法创建应用程序 com.app.MyApp:java.lang.NullPointerException:FirebaseCrashlytics 组件不存在

Nit*_*sta 7 android gradle firebase crashlytics-android

从 crashlytics 迁移到 firebase SDK 并升级 gradle 插件版本时,仅在启用 r8 的发布版本上发生此崩溃

注意:我在 build.gradle 以及应用程序类中定义和设置了 multidex 依赖项。仅当我将 gradle 插件版本从 3.5 升级到 4.1 时才会发生这种情况

我正在使用 firebase-crashlytics 版本

implementation 'com.google.firebase:firebase-crashlytics:17.0.0'
Run Code Online (Sandbox Code Playgroud)

等级插件版本

classpath 'com.android.tools.build:gradle:4.0.1'
Run Code Online (Sandbox Code Playgroud)

Crashlytics gradle 插件版本

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
Run Code Online (Sandbox Code Playgroud)

我还在 logcat 中收到警告

W/ComponentDiscovery: Class com.google.firebase.crashlytics.CrashlyticsRegistrar is not an found.
    java.lang.ClassNotFoundException: com.google.firebase.crashlytics.CrashlyticsRegistrar

 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.crashlytics.CrashlyticsRegistrar" on path: DexPathList


W/ComponentDiscovery: Class com.google.firebase.auth.FirebaseAuthRegistrar is not an found.
    java.lang.ClassNotFoundException: com.google.firebase.auth.FirebaseAuthRegistrar

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.auth.FirebaseAuthRegistrar" on path: DexPathList

W/ComponentDiscovery: Class com.google.firebase.database.DatabaseRegistrar is not an found.
    java.lang.ClassNotFoundException: com.google.firebase.database.DatabaseRegistrar

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.database.DatabaseRegistrar" on path: DexPathList
Run Code Online (Sandbox Code Playgroud)

为了摆脱上述警告,我在 android 清单中的应用程序标签下添加了以下内容

 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
      <meta-data
          android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
          android:value="com.google.firebase.components.ComponentRegistrar" />
      <meta-data
          android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar"
          android:value="com.google.firebase.components.ComponentRegistrar"/>
      <meta-data
          android:name="com.google.firebase.components:com.google.firebase.crashlytics.CrashlyticsRegistrar"
          android:value="com.google.firebase.components.ComponentRegistrar"/>

    </service>
Run Code Online (Sandbox Code Playgroud)

仍然没有运气。完成所有这些之后我看到了这个

java.lang.RuntimeException: Unable to create application com.app.MyApp: java.lang.NullPointerException: FirebaseCrashlytics component is not present
Run Code Online (Sandbox Code Playgroud)

当我尝试访问时出现 NPE

FirebaseCrashlytics.getInstance();
Run Code Online (Sandbox Code Playgroud)

Mon*_*ser -1

尝试在 Gradle(应用程序)中添加 Firebase-BOM。

implementation platform('com.google.firebase:firebase-bom:26.1.1')
Run Code Online (Sandbox Code Playgroud)

然后在你的应用程序类中而不是

FirebaseCrashlytics.getInstance();
Run Code Online (Sandbox Code Playgroud)

使用

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
Run Code Online (Sandbox Code Playgroud)