英文:
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.bottomnav
问题
我制作了我的应用的基本版本,其中包括了 Firebase 身份验证,在将应用程序与 Firebase 连接之前,我在 Android 模拟器中对应用程序进行了测试。我遇到了以下错误,然后我自己修复了一些问题。
- 连接了 Firebase
- 添加了依赖项
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 工具会自动完成所有操作。那么,我可能漏掉了哪个步骤吗?
英文:
I made the basic version of my app which included Firebase Authentication and before I connected the app with firebase, I tested the app in the Android Emulator. I got the following error and then I fixed few things on my own.
-connected the firebase
-added the dependency
classpath 'com.google.gms:google-services:4.2.0'
Still the following error is encountered -
/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)
I have used the Firebase tool in my earlier projects and I am under the impression that using the in-built firebase tool within the Android Studio does everything automatically. So, is there any step that I may have skipped?
答案1
得分: 7
对我来说,问题出在使用了 Google 服务插件版本 4.3.9。只需要将:
classpath 'com.google.gms:google-services:4.3.9'
更改为:
classpath 'com.google.gms:google-services:4.3.8'
英文:
for me, the issue was using google service plugin version 4.3.9. just
change
classpath 'com.google.gms:google-services:4.3.9'
to
classpath 'com.google.gms:google-services:4.3.8'
答案2
得分: 3
你可能没有将google-services插件添加到你的build.gradle中。它不仅仅是一个依赖项。根据文档,你还需要添加:
apply plugin: 'com.google.gms.google-services'
英文:
You probably did not add the google-services plugin to your build.gradle. It's more than just a dependency. According to the documentation, you also have to add:
apply plugin: 'com.google.gms.google-services'
答案3
得分: 1
答案非常简单,您应该在built.gradle
的依赖项中添加一个类路径 'com.google.gms:google-services:4.3.8',然后在built.gradle(app)
中添加id 'com.google.gms.google-services',就是这样。
英文:
The answer is very simple you should add a classpath 'com.google.gms:google-services:4.3.8' in dependencies of built.gradle and then add id 'com.google.gms.google-services' in built.gradle(app) that's all.
答案4
得分: 0
在第一个活动的onCreate()方法中或在应用程序类中,在执行任何与Firebase相关的操作之前初始化Firebase:
FirebaseApp.initializeApp(this);
英文:
Initialize firebase on the first activity onCreate() or in application class before performing any action with firebase
FirebaseApp.initializeApp(this)
答案5
得分: 0
在build.gradle
的插件中添加 id 'com.google.gms.google-services'
,你就不会遇到问题。
英文:
Add id 'com.google.gms.google-services'
in the plugins of build.gradle
and you won't have an issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论