我制作了应用程序的基本版本,其中包括Firebase身份验证,在将应用程序与Firebase连接之前,我在Android Emulator中测试了该应用程序。我犯了以下错误,然后我自己解决了一些问题
-连接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工具可以自动完成所有任务。那么,有没有我可能跳过的步骤?
对我来说,问题是使用谷歌服务插件4.3.9版本。只是更改
classpath 'com.google.gms:google-services:4.3.9'
至
classpath 'com.google.gms:google-services:4.3.8'
您可能没有将谷歌服务插件添加到您的build.gradle中。它不仅仅是一个依赖项。根据文档,您还必须添加:
apply plugin: 'com.google.gms.google-services'
答案很简单,你应该在built.gradle的依赖项中添加一个类路径'com.google.gms:google services:4.3.8',然后在build.gradle(应用程序(中添加id`com.google.gms.google services'。
在使用firebase执行任何操作之前,在第一个活动onCreate((或应用程序类中初始化firebaseFirebaseApp.initializeApp(此(
在build.gradle
的插件中添加id 'com.google.gms.google-services'
就不会有问题。