确保首先调用 FirebaseApp.initializeApp(Context)。默认 FirebaseApp 未在此过程中初始化 com.example.login
Posted
技术标签:
【中文标题】确保首先调用 FirebaseApp.initializeApp(Context)。默认 FirebaseApp 未在此过程中初始化 com.example.login【英文标题】:Make sure to call FirebaseApp.initializeApp(Context) first. Default FirebaseApp is not initialized in this process com.example.login 【发布时间】:2019-09-06 15:00:47 【问题描述】:我正在使用 kotlin 创建 Firebase 身份验证注册页面,并且在运行应用程序时出现运行时错误。 请看第 3 行和第 14 行我不知道是什么问题。
我没有附上主要代码,如果需要附上代码,请告诉我。
E/androidRuntime: FATAL EXCEPTION: main
Process: com.example.login, PID: 7505
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.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.
实施
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
【问题讨论】:
请在您的应用级别添加apply plugin: 'com.google.gms.google-services'
build.gradle
。作为最后一个。喜欢:prntscr.com/ncpwui
那么你用过FirebaseApp.initializeApp(Context)吗?
@AjayMehta-Rlogical 它已经存在了
@Piyush 我没用过
你必须使用那个
【参考方案1】:
添加此行build.gradle(Project)
classpath 'com.google.gms:google-services:4.3.3'
并添加这个插件build.gradle(module)
apply plugin: 'com.google.gms.google-services'
【讨论】:
【参考方案2】:不要在项目级 build.gradle 的行下方添加,而是将其添加到应用级 gradle 中。
应用插件:'com.google.gms.google-services'
【讨论】:
【参考方案3】:我有类似的东西,因为我忘了添加
apply plugin: 'com.google.gms.google-services'
在 build.gradle 的底部
【讨论】:
【参考方案4】:谢谢大家,但我自己解决了。我所做的只是
classpath 'com.google.gms:google-services:4.1.0'
到
classpath 'com.google.gms:google-services:4.2.0'
这对我有用!
【讨论】:
我有类路径 'com.google.gms:google-services:4.3.3' 但我收到了错误 它应该与classpath
和apply plugin
一起使用。只有一个是没有意义的。以上是关于确保首先调用 FirebaseApp.initializeApp(Context)。默认 FirebaseApp 未在此过程中初始化 com.example.login的主要内容,如果未能解决你的问题,请参考以下文章
默认 FirebaseApp 未在此进程 com.example.example 中初始化。确保首先调用 FirebaseApp.initializeApp(Context)
确保首先调用 FirebaseApp.initializeApp(Context)。默认 FirebaseApp 未在此过程中初始化 com.example.login