Critical Startup ANRs during FirebaseApp.initializeApp on Android

オープン
#2,754 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
静か
技術スタック
android, kotlin

調査の方向性

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:

  1. 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.
  2. 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.
  3. 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時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/quickstart-android のほかの issue

firebase/quickstart-android の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。