gpt4 book ai didi

Android - 在 Instant App 中初始化 Firebase - 获取异常

转载 作者:行者123 更新时间:2023-11-29 18:46:03 24 4
gpt4 key购买 nike

这是我的应用程序类:

包 com.example.myapp

import android.support.multidex.MultiDexApplication
import com.facebook.appevents.AppEventsLogger
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings

class App : MultiDexApplication() {
override fun onCreate() {
super.onCreate()

// Facebook
AppEventsLogger.activateApp(this)

// Firebase
FirebaseApp.initializeApp(this)

val settings = FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.setTimestampsInSnapshotsEnabled(true)
.build()

FirebaseFirestore.getInstance().firestoreSettings = settings
}
}

这是我遇到的错误。它在 App 类的最后一行 FirebaseFirestore.getInstance() 失败,说它没有初始化,但是你可以在上面看到我正在初始化它吗?

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp, PID: 8328
java.lang.RuntimeException: Unable to create application com.example.myapp.App: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.1:219)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.0.5:49)
at com.example.myapp.App.onCreate(App.kt:31)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
at android.app.ActivityThread.access$1100(ActivityThread.java:199) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

有人知道我需要做什么来解决这个问题吗?这是一个即时应用程序。我已将 google services json 放入每个模块(base + app + instant)中,并将插件添加到每个 gradle。

很奇怪,它显然已经通过了初始化语句,但仍然失败。

最佳答案

对我来说,任何地方给出的解决方案都没有用。只有这个有效。只需将我的谷歌服务从 4.1.0 下载到 4.0.0

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
classpath 'com.google.gms:google-services:4.0.0'
/*classpath 'com.google.gms:google-services:4.1.0' <-- this was the problem */
}

因此,如果您更新了 google 服务,只需尝试降级或更改为旧版本即可。

关于Android - 在 Instant App 中初始化 Firebase - 获取异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51918131/

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