我们在Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
刚刚添加 Firebase 远程配置的 Android 应用中看到了一些异常消息。
堆栈跟踪如下:
Fatal Exception: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.remoteconfig.FirebaseRemoteConfig.getInstance(Unknown Source)
at com.example.app.fragments.SomeFragment.updateFooter(SourceFile:295)
at com.example.app.fragments.SomeFragment.onCreateView(SourceFile:205)
at android.support.v4.app.Fragment.performCreateView(SourceFile:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1290)
at android.support.v4.app.BackStackRecord.run(SourceFile:801)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(SourceFile:1638)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(SourceFile:679)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(SourceFile:143)
at android.support.v4.view.ViewPager.populate(SourceFile:1240)
at android.support.v4.view.ViewPager.populate(SourceFile:1088)
at android.support.v4.view.ViewPager.setAdapter(SourceFile:542)
at com.example.app.SomeActivity.onSomeAsyncCallback(SourceFile:908)
at com.example.app.SomeDataRetriever.onAsyncHttpCompleted(SourceFile:72)
at com.example.app.io.AsyncHttp.onPostExecute(SourceFile:141)
at com.example.app.io.AsyncHttp.onPostExecute(SourceFile:19)
at android.os.AsyncTask.finish(AsyncTask.java:679)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:696)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
这是 9.6.1 版本,我们还使用其他 Firebase 组件:
compile 'com.google.firebase:firebase-ads:9.6.1'
compile 'com.google.firebase:firebase-config:9.6.1'
compile 'com.google.firebase:firebase-invites:9.6.1'
compile "com.google.firebase:firebase-messaging:9.6.1"
正如我从文档和Javadoc中看到的那样,在我们的案例中,我们不应该进行任何手动初始化。
该异常发生在各种设备上的 Android 4-6 上。
编辑:
我看到这个问题得到了一点关注。我认为这个解释对你们中的一些人来说可能很有趣:https ://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html