android - 默认FirebaseApp未初始化

标签 android firebase-remote-config

我们在Android应用程序中看到了Default FirebaseApp is not initialized in this process com.example.app. Make sure to call FirebaseApp.initializeApp(Context) first.消息的一些异常(exception)情况,我们刚刚在其中添加了Firebase Remote Config。

堆栈跟踪如下:

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"

正如我看到的from the documentationthe Javadoc一样,在这种情况下,我们不必手动进行任何初始化。

异常(exception)情况发生在各种设备上的Android 4-6上。

编辑:

我看到这个问题引起了一点关注。我认为对于某些人来说,这种解释可能很有趣:https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html

最佳答案

我前段时间也遇到过同样的问题。
您正在尝试获取Firebase实例而不对其进行初始化。
在尝试在主函数或FutureBuilder中获取Firebase实例之前,请添加以下代码行:

FirebaseApp.initializeApp();

关于android - 默认FirebaseApp未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63512704/

相关文章:

android - Firebase异常 : Failed to bounce to type in Android but Model class properties and JSON properties are same

java - 如何将多个 ImageView 保存为一个 Bitmap,同时保持 Android 中每个 ImageView 的位置?

flutter - 如何使用 Firebase 远程配置打开/关闭 Admob?

android - FirebaseRemoteConfig fetchAndActivate 不更新新值

android - Firebase 中与远程配置相关的缓存是什么?

java - 调用 .text() 方法时 Jsoup 元素不显示

android - 本地网络中的设备发现

firebase - 如何根据应用版本定义 firebase-remote-config 参数

redux - 如何在 flutter redux 中创建商店时从服务器异步加载应用程序状态?

android - Xamarin - Java 库监听器和事件?