安卓 java。lang.IllegalStateException:默认FirebaseApp未在此进程com中初始化。实例底部导航
我制作了我的应用程序的基本版本,其中包括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 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at 安卓.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at 安卓.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at 安卓.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at 安卓.os.Handler.dispatchMessage(Handler.java:106)
at 安卓.os.Looper.loop(Looper.java:223)
at 安卓.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.安卓.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 安卓.app.Activity.performCreate(Activity.java:8000)
at 安卓.app.Activity.performCreate(Activity.java:7984)
at 安卓.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
我在早期的项目中使用过Firebase工具,我的印象是在Android Studio中使用内置的Firebase工具可以自动完成所有工作。那么,有没有我可能跳过的步骤
# 1 楼答案
在对firebase执行任何操作之前,在第一个活动onCreate()或应用程序类中初始化firebase FirebaseApp。初始化EAPP(本)
# 2 楼答案
在
build.gradle
的插件中添加id 'com.google.gms.google-services'
,您就不会有问题了# 3 楼答案
对我来说,问题在于使用谷歌服务插件版本4.3.9。只是 改变
到
# 4 楼答案
您可能没有将google服务插件添加到您的构建中。格拉德尔。这不仅仅是一种依赖。根据documentation,您还必须添加:
# 5 楼答案
答案很简单,您应该添加一个classpath'com。谷歌。gms:googleservices:4.3.8'内置的依赖项。gradle,然后添加id'com。谷歌。gms。谷歌服务内置。gradle(应用程序)仅此而已