Firebase和Facebook发生ExceptionInInitializerError

时间:2019-01-29 22:50:35

标签: android firebase facebook-graph-api firebase-realtime-database firebase-authentication

我最近将firebase升级到了最新版本,现在正在使用服务器生成的自定义令牌进行身份验证。我也正在对Firebase实例进行自定义初始化,如此处https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html所述。初始化是在我的应用程序onCreate方法的第三行(在调用super并设置了静态实例变量之后)完成的,因此它可以尽早完成。

我收到以下异常,但是它不能始终如一地重现,因此看起来像是firebase和facebook sdks之间的某种竞争条件。

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    java.lang.ExceptionInInitializerError
        at com.google.firebase.perf.internal.RemoteConfigManager.zzcb(Unknown Source)
        at com.google.firebase.perf.internal.FeatureControl.<init>(Unknown Source)
        at com.google.firebase.perf.internal.FeatureControl.zzar(Unknown Source)
        at com.google.firebase.perf.internal.GaugeManager.<init>(Unknown Source)
        at com.google.firebase.perf.internal.GaugeManager.zzbf(Unknown Source)
        at com.google.android.gms.internal.firebase-perf.zzat.<init>(Unknown Source)
        at com.google.android.gms.internal.firebase-perf.zzat.zza(Unknown Source)
        at com.google.firebase.perf.network.FirebasePerfUrlConnection.instrument(Unknown Source)
        at com.facebook.GraphRequest.createConnection(GraphRequest.java:1410)
        at com.facebook.GraphRequest.toHttpConnection(GraphRequest.java:1070)
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1158)
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1134)
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1118)
        at com.facebook.GraphRequest.executeAndWait(GraphRequest.java:1093)
        at com.facebook.GraphRequest.executeAndWait(GraphRequest.java:987)
        at com.facebook.internal.FetchedAppSettingsManager.getAppSettingsQueryResponse(FetchedAppSettingsManager.java:207)
        at com.facebook.internal.FetchedAppSettingsManager.access$100(FetchedAppSettingsManager.java:47)
        at com.facebook.internal.FetchedAppSettingsManager$1.run(FetchedAppSettingsManager.java:122)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.coffeemeetsbagel. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.4:240)
        at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance(Unknown Source)
        at com.google.firebase.perf.internal.RemoteConfigManager.<init>(Unknown Source)
        at com.google.firebase.perf.internal.RemoteConfigManager.<clinit>(Unknown Source)
        at com.google.firebase.perf.internal.RemoteConfigManager.zzcb(Unknown Source) 
        at com.google.firebase.perf.internal.FeatureControl.<init>(Unknown Source) 
        at com.google.firebase.perf.internal.FeatureControl.zzar(Unknown Source) 
        at com.google.firebase.perf.internal.GaugeManager.<init>(Unknown Source) 
        at com.google.firebase.perf.internal.GaugeManager.zzbf(Unknown Source) 
        at com.google.android.gms.internal.firebase-perf.zzat.<init>(Unknown Source) 
        at com.google.android.gms.internal.firebase-perf.zzat.zza(Unknown Source) 
        at com.google.firebase.perf.network.FirebasePerfUrlConnection.instrument(Unknown Source) 
        at com.facebook.GraphRequest.createConnection(GraphRequest.java:1410) 
        at com.facebook.GraphRequest.toHttpConnection(GraphRequest.java:1070) 
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1158) 
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1134) 
        at com.facebook.GraphRequest.executeBatchAndWait(GraphRequest.java:1118) 
        at com.facebook.GraphRequest.executeAndWait(GraphRequest.java:1093) 
        at com.facebook.GraphRequest.executeAndWait(GraphRequest.java:987) 
        at com.facebook.internal.FetchedAppSettingsManager.getAppSettingsQueryResponse(FetchedAppSettingsManager.java:207)  

更新:删除Firebase性能插件似乎可以解决该问题;但是,我想要插件提供的自动跟踪功能,所以我想找到一个可以同时使用Firebase和Facebook的解决方案

2 个答案:

答案 0 :(得分:0)

Facebook说他们的android sdk当前与firebase性能插件不兼容。

https://developers.facebook.com/bugs/2046702775626929/

答案 1 :(得分:0)

问题的原因似乎是Facebook SDK尝试在Firebase Performance初始化之前发出网络请求。我找到了一种解决方案,可以强制Firebase在facebook之前初始化。

  1. 在Android清单中删除Firebase和Facebook的“初始提供程序”。这些在每个SDK中使用,以自动初始化每个库。 2.然后,您可以从Application onCreate方法手动初始化每个库,并在Facebook之前调用Firebase。

在您的AndroidManifest.xml文件中:

    <!--Init Firebase manually in Application class-->
    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="${applicationId}.firebaseinitprovider"
        tools:node="remove"
        />

    <!--Init Facebook manually in Application class-->
    <provider
        android:name="com.facebook.internal.FacebookInitProvider"
        android:authorities="${applicationId}.FacebookInitProvider"
        tools:node="remove"/>

在您的应用程序类中

@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
    FacebookSdk.sdkInitialize(this);
}

我认为这不是一个很好的解决方案,但它确实可以完成工作,直到Facebook或Firebase更新它们的库以停止应用程序启动期间的冲突为止。