gpt4 book ai didi

android - IllegalStateException : Default FirebaseApp is not initialized in this process. 确保先调用 FirebaseApp.initializeApp(Context)

转载 作者:行者123 更新时间:2023-11-29 02:18:50 28 4
gpt4 key购买 nike

在更改了一些 gradle 依赖项后,我今天遇到了这个 fatal error 。即使我试图将 gradle 依赖恢复到原来的状态,我仍然在这一行收到错误:

class MainActivity : AppCompatActivity() {

val db = FirebaseFirestore.getInstance() // IllegalStateException

错误:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.app/com.app.MainActivity}: 

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.app. Make sure to call FirebaseApp.initializeApp(Context) first.

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.app. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@17.1.0:186)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@20.1.0:70)
at com.app.MainActivity.<init>(MainActivity.kt:43)

渐变(应用程序)

apply plugin: 'com.google.gms.google-services'

dependencies {

// Firebase
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.google.firebase:firebase-firestore:20.1.0'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.firebaseui:firebase-ui-storage:4.3.2'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-functions:17.0.0'

}

gradle(项目)

buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
}

根据多个答案1 2问题与 google-services 依赖项有关 - 我已将其更改为推荐版本 4.2.0 - 但我仍然遇到相同的错误。

知道如何修复它吗?

编辑:

这是重复的,因为建议的答案 FirebaseApp.initializeApp(this) 没有解决问题。

编辑 2:我的模拟器没有错误,只有我的设备有错误

最佳答案

我尝试使用 Android Studio(3.5) 助手设置 Firebase。

这是他们向我展示的建议注入(inject)的依赖项

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

在应用程序 build.gradle 中

apply plugin: 'com.google.gms.google-services'

implementation 'com.google.firebase:firebase-auth:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-functions:16.0.4'

You don't need to add all these dependencies, just add the required ones only. Otherwise the APK will get larger.

关于android - IllegalStateException : Default FirebaseApp is not initialized in this process. 确保先调用 FirebaseApp.initializeApp(Context),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57737059/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com