Android 确保首先调用FirebaseApp.initializeApp(上下文)。默认FirebaseApp未在此进程com.example.login中初始化

Android 确保首先调用FirebaseApp.initializeApp(上下文)。默认FirebaseApp未在此进程com.example.login中初始化,android,firebase,firebase-realtime-database,kotlin,firebase-authentication,Android,Firebase,Firebase Realtime Database,Kotlin,Firebase Authentication,我正在使用kotlin创建Firebase身份验证注册页,运行应用程序时出现运行时错误。 请看第3行和第14行,我不知道是什么问题 我没有附上主代码。如果需要附上代码,请通知我 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.login, PID: 7505 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{co

我正在使用kotlin创建Firebase身份验证注册页,运行应用程序时出现运行时错误。 请看第3行和第14行,我不知道是什么问题

我没有附上主代码。如果需要附上代码,请通知我

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.login, PID: 7505
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.login/com.example.login.Register}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.login. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.login. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
        at com.example.login.Register.<init>(Register.kt:15)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Application terminated.

谢谢大家,但我自己解决了。我所做的只是

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


这对我有用

我有类似的东西,因为我忘了添加

应用插件:“com.google.gms.google服务”


在build.gradle的底部

将其添加到应用程序级gradle中,而不是添加到项目级build.gradle中的行下方


应用插件:“com.google.gms.google服务”

添加此行
build.gradle(项目)

并添加此插件
build.gradle(模块)


请在您的应用程序级别
build.gradle
中添加
apply插件:“com.google.gms.google服务”
。作为最后一个。比如:你用过FirebaseApp.initializeApp(上下文)吗?@AjayMehta Rlogical已经用过了there@Piyush我没有使用,你必须使用,我有类路径'com.google.gms:google services:4.3.3',但我得到了错误,它应该与
classpath
apply plugin
一起使用。只有一个是没有意义的。
classpath 'com.google.gms:google-services:4.1.0'
classpath 'com.google.gms:google-services:4.2.0'
  classpath 'com.google.gms:google-services:4.3.3' 
apply plugin: 'com.google.gms.google-services'