您好,我正在尝试为其发布版本构建我们的应用程序,但首次运行该应用程序时会触发以下错误。
复制步骤:
FATAL EXCEPTION: main
Process: silicon.android.app.alpha, PID: 7837
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at android.app.ActivityThread.installProvider(ActivityThread.java:7493)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6999)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6770)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.google.firebase.components.AbstractComponentContainer.setOf(Unknown Source:220)
at com.google.firebase.components.ComponentRuntime.setOf(ComponentRuntime.java:46)
at com.google.firebase.components.RestrictedComponentContainer.setOf(RestrictedComponentContainer.java:150)
at com.google.firebase.heartbeatinfo.DefaultHeartBeatController.lambda$component$4(DefaultHeartBeatController.java:157)
at com.google.firebase.heartbeatinfo.DefaultHeartBeatController$$ExternalSyntheticLambda3.create(Unknown Source:0)
at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0$com-google-firebase-components-ComponentRuntime(ComponentRuntime.java:140)
at com.google.firebase.components.ComponentRuntime$$ExternalSyntheticLambda1.get(Unknown Source:4)
at com.google.firebase.components.Lazy.get(Lazy.java:53)
at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:606)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:307)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:271)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:256)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
at android.app.ActivityThread.installProvider(ActivityThread.java:7488)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6999)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6770)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
巧合的是,这仅在发布时运行,但在调试时运行良好。我已将 -dontshrink、-dontoptimize、-dontobfuscate 添加到我的 proguard 规则中,这就是我可以生成堆栈跟踪的原因。
构建 Gradle 价值观
android {
compileSdkVersion 33
buildToolsVersion "33.0.0"
defaultConfig {
minSdkVersion 23
targetSdkVersion 33
versionCode 1
versionName '0.1.0'
consumerProguardFiles "consumer-rules.pro"
}
minifyEnabled、textCoverageEnabled、shrinkResources 全部变成 false
Firebase 库
"analytics" : "com.google.firebase:firebase-analytics-ktx",
"crashlytics": "com.google.firebase:firebase-crashlytics-ktx",
"config" : "com.google.firebase:firebase-config-ktx",
对于所有可能遇到此问题的人来说,这是因为 Dexguard 混淆与我正在使用的某些库发生冲突。在这种情况下,firebase 库、crashlytics 和脱糖 SDK 值得注意。
将 firebase 和脱糖 SDK 降到旧版本解决了我的问题。
如果您下次遇到这种情况,请仔细检查您的提交并查找 SDK 依赖项更新。从那里开始,因为日志不会有任何帮助。
祝你好运!
java.lang.RuntimeException:81055174 在 com.google.firebase.perf.provider.FirebasePerfProvider.onCreate(未知来源:2379) 在 android.content.ContentProvider.attachInfo(ContentProvider.java:2574) 在 android.content.ContentProvider.attachInfo(ContentProvider.java:2544) 在 com.google.firebase.perf.provider.FirebasePerfProvider.attachInfo(:8) 在 android.app.ActivityThread.installProvider(ActivityThread.java:8192) 在 android.app.ActivityThread.installContentProviders(ActivityThread.java:7677) 在 android.app.ActivityThread.handleBindApplication(ActivityThread.java:7393) 在 android.app.ActivityThread.-$$Nest$mhandleBindApplication(来源未知:0) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2410) 在 android.os.Handler.dispatchMessage(Handler.java:106) 在 android.os.Looper.loopOnce(Looper.java:223) 在 android.os.Looper.loop(Looper.java:324) 在 android.app.ActivityThread.main(ActivityThread.java:8630) 在java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1061)