Critical Startup ANRs during FirebaseApp.initializeApp on Android
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 领域
- mobile, performance
调研方向
从 Application.kt 和 FirebaseUtil.initFirebase 开始,然后检查 AndroidManifest.xml 中移除 FirebaseInitProvider 的改动,以及报告的 FirebaseApp.initializeApp 堆栈跟踪。如果可能,请在列出的低端至中端 Android 设备上复现启动过程,并确定是初始化过程还是某个 eager 组件阻塞了主线程;当启动 ANR 得到解决且结果已在跟踪记录中验证后,即视为完成。
由索引模型根据 Issue 内容生成。
描述
- Android device: oppo,xiaomi,Transsion,vivo
- Android OS version: 13,14,15,16
- Google Play Services version: Unable to determine the GMS version on the user's phone
- Firebase/Play Services SDK version: com.google.firebase:firebase-bom:33.9.0
Step 2: Describe the problem:
We are experiencing a high volume of startup ANRs (Application Not Responding) on our production Android app, specifically during the Firebase initialization process.
History of Attempts to Fix:
- Initial State: We used the default automatic initialization via FirebaseInitProvider . This resulted in significant startup ANRs as reported by Google Play Console and Firebase Crashlytics.
- Current Implementation: To optimize startup performance, we disabled the automatic initialization in AndroidManifest.xml and moved the initialization to a manual call within the Application.onCreate() method.
- Outcome: Unfortunately, the ANR rate has not improved. The main thread still gets blocked during the manual call to FirebaseApp.initializeApp
Steps to reproduce:
Clicking the icon to launch the application may reproduce this issue on low- to mid-range devices. The screen remains black and unresponsive upon launch.The ANR tracker consistently shows that the main thread is stuck at FirebaseApp.initializeApp. It appears that internal components (such as Analytics or Crashlytics) are performing time-consuming synchronous I/O or lock contention during initialization.
Relevant Code:
// In Application.kt
override fun onCreate() {
super.onCreate()
// Manual initialization to avoid ContentProvider blocking
FirebaseUtil.initFirebase(this)
}
fun initFirebase(context: Application) {
runCatching {
val option = FirebaseOptions.Builder().apply {
setApplicationId(AppConstants.APP_ID_RESOURCE_NAME)
setApiKey(AppConstants.API_KEY_RESOURCE_NAME)
setProjectId(AppConstants.PROJECT_ID_RESOURCE_NAME)
setGcmSenderId(AppConstants.GCM_SENDER_ID_RESOURCE_NAME)
setStorageBucket(AppConstants.STORAGE_BUCKET_RESOURCE_NAME)
}.build()
// This call is identified as the main thread blocker in ANR traces
firebaseApp = FirebaseApp.initializeApp(context, option)?.apply {
setAutomaticResourceManagementEnabled(true)
}
}
}
In AndroidManfiest.xml
ANR traces::
main (runnable):tid=1 systid=5624
at com.google.firebase.crashlytics.internal.common.CrashlyticsReportDataCapture.(CrashlyticsReportDataCapture.java:14)
at com.google.firebase.crashlytics.internal.common.SessionReportingCoordinator.create(SessionReportingCoordinator.java:75)
at com.google.firebase.crashlytics.internal.common.CrashlyticsCore.onPreExecute(CrashlyticsCore.java:163)
at com.google.firebase.crashlytics.FirebaseCrashlytics.init(FirebaseCrashlytics.java:168)
at com.google.firebase.crashlytics.CrashlyticsRegistrar.buildCrashlytics(CrashlyticsRegistrar.java:79)
at com.google.firebase.tracing.ComponentMonitor.lambda$processRegistrar$0(ComponentMonitor.java:38)
at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0(ComponentRuntime.java:160)
at com.google.firebase.components.Lazy.get(Lazy.java:53)
at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:322)
at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:312)
at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:607)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:300)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
at com.xxx.xxx.FirebaseUtil.initFirebase(FirebaseUtil.java:63)
at com.xxx.xxx.Application.onCreate(Application.kt:138)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1386)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7648)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(unavailable)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2477)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8886)
at java.lang.reflect.Method.invoke(Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:681)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:915)
- 主要语言
- Kotlin
- 星标
- 9.3k
- 派生
- 7.4k
- 平均合并
- 7 天 9 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/quickstart-android 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
firebase/quickstart-android#2756 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 32/100
firebase/quickstart-android#2668 ·
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/quickstart-android#2663 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/quickstart-android#1669 · 3 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/quickstart-android#1580 · 1 条评论 ·
查看 firebase/quickstart-android 的全部 Issue
相似的 Issue
-
android:plan main:plan packages:learn
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
Needs Triage
难度 2/5 1-3 小时 新手友好度 72/100
ankidroid/Anki-Android#23453 ·
维护者通常 1 天内回复
-
afk-ok area:data-quality importer size:S
难度 2/5 1-3 小时 新手友好度 78/100
enorm-labs/event-junkie#5278 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
bazel-contrib/rules_kotlin#1846 ·
维护者通常 2 天内回复