firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.29k stars 579 forks source link

ANRs after switching to custom Firebase initialization via ContentProvider #6393

Closed nesterenko1pavel closed 1 month ago

nesterenko1pavel commented 1 month ago

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

After changes in application (according to Take Control of Your Firebase Init on Android) i.e. after custom ContentProvider was created I started getting crashes in crashlytics. There are 10k crashes so far. But problem dose not occur locally - I tried a lot different devices but without success to reproduce.

Relevant Code: DynamicContentProvider

override fun onCreate(): Boolean {
    val nonNullableContext = context ?: return false

    val firebaseSecuredWrapper = FirebaseSecuredWrapper(...)

    val model = firebaseSecuredWrapper.get()

    val options = if (model != null) {
        FirebaseOptions.Builder()
            .setGcmSenderId(model.gcmSenderId)
            .setApiKey(model.apiKey)
            .setApplicationId(model.applicationId)
            .setStorageBucket(model.storageBucket)
            .setProjectId(model.projectId)
            .build()
    } else {
        FirebaseOptions.fromResource(nonNullableContext)
    }

    FirebaseApp.initializeApp(nonNullableContext, requireNotNull(options))

    return false
}

I am getting Triggered ANR Root blocking at my.application.provider.DynamicContentProvider.onCreate(DynamicContentProvider.kt:45), i.e at FirebaseApp.initializeApp(nonNullableContext, requireNotNull(options))

Messages from crashlytics:

          main (runnable):tid=1 systid=8338 
       at java.lang.String.concat(Native method)
       at com.google.firebase.crashlytics.internal.common.ExecutorUtils.addDelayedShutdownHook(ExecutorUtils.java:96)
       at com.google.firebase.crashlytics.internal.common.ExecutorUtils.addDelayedShutdownHook(ExecutorUtils.java:87)
       at com.google.firebase.crashlytics.internal.common.ExecutorUtils.buildSingleThreadExecutorService(ExecutorUtils.java:40)
       at com.google.firebase.crashlytics.FirebaseCrashlytics.init(FirebaseCrashlytics.java:87)
       at com.google.firebase.crashlytics.CrashlyticsRegistrar.buildCrashlytics(CrashlyticsRegistrar.java:57)
       at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0(ComponentRuntime.java:140)
       at com.google.firebase.components.Lazy.get(Lazy.java:53)
       at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:302)
       at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:292)
       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 my.application.provider.DynamicContentProvider.onCreate(DynamicContentProvider.kt:45)
          main (runnable):tid=1 systid=11199 
       at com.google.firebase.crashlytics.CrashlyticsRegistrar.getComponents(CrashlyticsRegistrar.java:39)
       at com.google.firebase.tracing.ComponentMonitor.processRegistrar(ComponentMonitor.java:28)
       at com.google.firebase.components.ComponentRuntime.discoverComponents(ComponentRuntime.java:117)
       at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:99)
       at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:46)
       at com.google.firebase.components.ComponentRuntime$Builder.build(ComponentRuntime.java:387)
       at com.google.firebase.FirebaseApp.<init>(FirebaseApp.java:439)
       at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:296)
       at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
       at my.application.provider.DynamicContentProvider.onCreate(DynamicContentProvider.kt:45)
          main (runnable):tid=1 systid=5685 
       at java.util.Formatter$FormatSpecifier.precision(Formatter.java:2989)
       at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:3042)
       at java.util.Formatter$FormatSpecifierParser.<init>(Formatter.java:2804)
       at java.util.Formatter.parse(Formatter.java:2737)
       at java.util.Formatter.format(Formatter.java:2686)
       at java.util.Formatter.format(Formatter.java:2640)
       at java.lang.String.format(String.java:4068)
       at com.google.firebase.concurrent.CustomThreadFactory.newThread(CustomThreadFactory.java:50)
       at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:639)
       at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:929)
       at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1362)
       at com.google.firebase.concurrent.DelegatingScheduledExecutorService.execute(DelegatingScheduledExecutorService.java:104)
       at com.google.android.gms.tasks.Tasks.call(Tasks.java:5)
       at com.google.firebase.heartbeatinfo.DefaultHeartBeatController.registerHeartBeat(DefaultHeartBeatController.java:62)
       at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:608)
       at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:300)
       at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
       at my.application.provider.DynamicContentProvider.onCreate(DynamicContentProvider.kt:45)
google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

lehcar09 commented 1 month ago

Hi @nesterenko1pavel, thank you for reporting the issue. I tried reproducing the issue by using the code snippet you shared, however, I did not encounter any ANRs.

I noticed that you’re using an old Firebase SDK version (BOM v29.3.0). Could you try updating to the latest version (BOM v33.5.0) to ensure that you have the latest bug fixes that might be causing these issues?

Aside from that, did you notice if there’s a common API version where this issue occurs? You mentioned that the ANR happened after changing to manual initialization, could you share the Firebase SDK version you’re using prior to these changes? If possible, can you share your Gradle files?

nesterenko1pavel commented 1 month ago

@lehcar09 Unfortunately my team can see Crashes only at Firebase Crashlytics. When I run application locally - it it unable to reproduce no matter how much I tested. You'r right - now use old version of Firebase SDK. We noticed that too. We have plan to update version, but it'll be at the beginning of the next year due to lots of other features that are currently introducing. Maybe we will decide to do it earlier in case of sharp increasing of crashes.

Project files unfortunately are under NDA. I can share particular info from Gradle files but not all. Can you elaborate on what are you interested in?

lehcar09 commented 1 month ago

Could you share the versions that you're using for:

nesterenko1pavel commented 1 month ago

Android Gradle Plugin 8.2.2 Google Play Services "4.4.1" Crashlytics Gradle Plugin "2.9.9"

firebase-bom "29.3.0" firebase-analytics = { module = "com.google.firebase:firebase-analytics" } firebase-config-ktx = { module = "com.google.firebase:firebase-config-ktx" } firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics" } firebase-messaging = { module = "com.google.firebase:firebase-messaging" } firebase-pref-ktx = { module = "com.google.firebase:firebase-perf-ktx" }

firebase-ml-vision "24.1.0" firebase-perf-plugin "1.4.2"

lehcar09 commented 1 month ago

Thank you for sharing those details @nesterenko1pavel. Unfortunately, I still wasn’t able to reproduce the issue. I’m thinking if the issue is caused by some race condition. However, I can’t say anything for sure. Without continuously reproducing the issue it will be hard to investigate the issue.

For now, I highly suggest updating to the latest Firebase SDK version (BOM V33.5.1) just to make sure that you have the latest bug fixes and improvements.

That said, I’ll close this issue now. If the issue persists after updating to the latest version, please file a new issue with the details that can help us investigate the issue.