gpt4 book ai didi

android - FirebaseApp.initializeApp(this) 崩溃 NullPointerException

转载 作者:行者123 更新时间:2023-12-05 00:01:48 24 4
gpt4 key购买 nike

我的应用类如下:

override fun onCreate() {
super.onCreate()
FirebaseApp.initializeApp(this)
FirebaseCrashlytics.getInstance()
}

FirebaseApp.initializeApp(this) 在除我们之外的许多设备上崩溃(我们在 20 多台设备上测试并且运行良好)

崩溃报告取自 Google Play 控制台,其堆栈跟踪为:

java.lang.RuntimeException: 
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6737)
at android.app.ActivityThread.access$2000 (ActivityThread.java:273)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2020)
at android.os.Handler.dispatchMessage (Handler.java:112)
at android.os.Looper.loop (Looper.java:216)
at android.app.ActivityThread.main (ActivityThread.java:7625)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
Caused by: java.lang.NullPointerException:
at androidx.core.os.UserManagerCompat.isUserUnlocked (UserManagerCompat.java:42)
at com.google.firebase.FirebaseApp.initializeAllApis (FirebaseApp.java:573)
at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:302)
at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:266)
at com.google.firebase.FirebaseApp.initializeApp (FirebaseApp.java:251)
at com.superapp.MyApplication.onCreate (MyApplication.kt:92)
at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1162)
at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6717)
at android.app.ActivityThread.access$2000 (ActivityThread.java:273)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2020)
at android.os.Handler.dispatchMessage (Handler.java:112)
at android.os.Looper.loop (Looper.java:216)
at android.app.ActivityThread.main (ActivityThread.java:7625)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)

项目级build.gradle:

repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://plugins.gradle.org/m2/' }
maven {
url 'https://developer.huawei.com/repo/'
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath "com.google.gms:google-services:4.3.3"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.4.1"
classpath "com.huawei.agconnect:agcp:1.6.0.300"
classpath "de.timfreiheit.resourceplaceholders:placeholders:0.3"
classpath "com.google.firebase:firebase-appdistribution-gradle:1.3.1"
classpath "org.jacoco:org.jacoco.core:0.8.7"
}

app模块级build.gradle:

// at the top
apply plugin: "com.android.application"
apply plugin: "com.google.firebase.crashlytics"
apply plugin: "de.timfreiheit.resourceplaceholders"
apply plugin: "com.google.firebase.appdistribution"
apply plugin: "com.huawei.agconnect"

// at the bottom
apply plugin: "com.google.gms.google-services"

崩溃发生在 API 级别 28、29、30、31 和 32

这是 Google 的问题还是我们做错了什么?

最佳答案

这可能是 UserManagerCompat 中的错误,但通常调用 init 对于大多数应用程序来说不是必需的,这可能会缓解您的问题:

For a vast majority of apps, FirebaseInitProvider will handle the initialization of Firebase for the default project that it's configured to work with, via the data contained in the app's google-services.json file. This ContentProvider is merged into the app's manifest by default when building with Gradle, and it runs automatically at app launch. No additional lines of code are needed in this case.

https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp

如果您无法避免调用 initializeApp,您可以考虑调整谷歌服务版本以避免此答案中的错误:

Make sure to call FirebaseApp.initializeApp(Context) first in Android

关于android - FirebaseApp.initializeApp(this) 崩溃 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72543035/

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