即时应用程序-具有can-firestore错误的功能模块默认FirebaseApp在此过程中未初始化


  • 当我用我的应用程序实现Firebase时,我会收到类似"Default Firebase is not initialized"的错误。

  • 应用程序模块运行良好,但即时应用程序崩溃并显示以下错误。

在此过程中未初始化默认FirebaseApp。确保首先调用FirebaseApp.initializeApp(Context(。

我的Android代码,依赖项,模块::

**gradle file feature module(base-product).**
apply plugin: 'com.android.feature'
android {
compileSdkVersion 27
baseFeature true
}
dependencies {
}
**module:instantapp gradle file is:**
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':base-product')
}
apply plugin: 'com.google.gms.google-services'
**app: gradle**
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

模块:第一行中的Java文件:

FirebaseFirestore.getInstance().collection(cId).document(dId).
addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(DocumentSnapshot qs, FirebaseFirestoreException e) {
if (qs.exists()) ... });
  • 为基础模块和应用程序模块中的相同fire基础数据库添加了具有2个包名的Json文件

下面是我的堆栈跟踪::

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.zobaze.base.product. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(SourceFile:49)
at com.zobaze.base.product.ItemListActivity.onCreate(ItemListActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6672)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

如果您在feature中有应用程序类,请在onCreate方法中添加FirebaseApp.initializeApp(this)

之所以会出现这种情况,是因为firebase插件并没有在自动(如应用程序(中做到这一点

相关内容

最新更新