【问题标题】:java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.bottomnavjava.lang.IllegalStateException:默认 FirebaseApp 未在此过程中初始化 com.example.bottomnav
【发布时间】:2021-01-30 16:34:00
【问题描述】:

我制作了包含 Firebase 身份验证的应用程序的基本版本,在将应用程序与 firebase 连接之前,我在 Android 模拟器中测试了该应用程序。我收到以下错误,然后我自己修复了一些问题。
- 连接火力基地
-添加了依赖
classpath 'com.google.gms:google-services:4.2.0'

还是遇到下面的错误-

/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.bottomnav, PID: 2049
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bottomnav/com.example.bottomnav.login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.bottomnav. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.bottomnav. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@19.3.0:184)
        at com.google.firebase.auth.FirebaseAuth.getInstance(com.google.firebase:firebase-auth@@19.3.1:1)
        at com.example.bottomnav.login.onCreate(login.java:40)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)

我在早期的项目中使用过 Firebase 工具,我的印象是使用 Android Studio 中的内置 firebase 工具可以自动完成所有工作。那么,有没有我可能跳过的步骤?

【问题讨论】:

    标签: java android firebase firebase-authentication


    【解决方案1】:

    对我来说,问题在于使用 google 服务插件版本 4.3.9。只是 改变

            classpath 'com.google.gms:google-services:4.3.9'  
    

           classpath 'com.google.gms:google-services:4.3.8'  
    

    【讨论】:

      【解决方案2】:

      您可能没有将 google-services 插件添加到您的 build.gradle。它不仅仅是一种依赖。根据documentation,还得加:

      apply plugin: 'com.google.gms.google-services'
      

      【讨论】:

        【解决方案3】:

        答案很简单,你应该在built.gradle的依赖项中添加一个类路径'com.google.gms:google-services:4.3.8',然后添加id 'com .google.gms.google-services' 在 built.gradle(app) 中就是这样。

        【讨论】:

          【解决方案4】:

          在使用 firebase 执行任何操作之前,在第一个活动 onCreate() 或应用程序类中初始化 firebase FirebaseApp.initializeApp(this)

          【讨论】:

          • 您不需要包含 FirebaseApp.initializeApp(this)。我使用 Firebase Cloud Firestore 和 Firebase 身份验证制作了很多应用程序,但从未包含过这个。
          【解决方案5】:

          build.gradle的插件中添加id 'com.google.gms.google-services'就没有问题了。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-08-16
            • 1970-01-01
            • 2017-10-25
            • 2019-07-05
            • 2019-08-18
            • 1970-01-01
            • 1970-01-01
            • 2019-02-06
            相关资源
            最近更新 更多