firebase-ios-sdk
firebase-ios-sdk copied to clipboard
Cannot get new Crashlytics instance after deleting and recreating default FirebaseApp
Description
We need to change default firebase app configuration at some point in our application, and want to get a Crashlytics instance for this new default app (which has a different configuration than the previous one).
So we start by deleting current default application doing FirebaseApp.app()?.delete().
Looking at code it should clear the associated container that keeps the Crashlytics cached instance:
// Remove all cached instances from the container before deleting the app.
[self.container removeAllCachedInstances];
But after configuring the new default app with custom configuration using FirebaseApp.configure(options: newOptions) we cannot get the associated new Crashlytics instance. We have this error message instead:
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
It seems related to this part of code:
if (!atomic_compare_exchange_strong(&_hasInitializedInstance, &expectedCalled, YES)) {
FIRCLSErrorLog(@"Cannot instantiate more than one instance of Crashlytics.");
return nil;
}
Meaning that _hasInitializedInstance is not resetted to false when the first FirebaseApp was deleted, and it's container cleared.
Reproducing the issue
FirebaseApp.configure()
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(true)
await FirebaseApp.app()?.delete()
FirebaseApp.configure(options: newOptions) // Set new options, maybe the problem occurs with default options too
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(true)
// Logs: 11.6.0 - [FirebaseCrashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
Firebase SDK Version
11.6.0
Xcode Version
16.0.0
Installation Method
N/A
Firebase Product(s)
Crashlytics
Targeted Platforms
iOS
Relevant Log Output
11.6.0 - [FirebaseCore][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://firebase.google.com/docs/ios/setup#initialize_firebase_in_your_app
11.6.0 - [FirebaseCore][I-COR000001] Configuring the default app.
11.6.0 - [FirebaseCore][I-COR000033] Data Collection flag is not set.
11.6.0 - [FirebaseCrashlytics][I-CLS000000] [Crashlytics] Running on iOS Simulator (iPhone), 18.0.0 (23H124)
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Registering Sessions SDK subscription for session data
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Session ID changed: ***
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Root: ***
11.6.0 - [FirebaseCrashlytics][I-CLS000000] [Crashlytics:Crash:Reports:Event] Firebase Analytics SDK not detected. Crash-free statistics and breadcrumbs will not be reported
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Automatic data collection is disabled.
11.6.0 - [FirebaseCrashlytics][I-CLS000000] [Crashlytics:Crash] 0 unsent reports are available. Waiting for send/deleteUnsentReports to be called.
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Sending unsent reports.
11.6.0 - [FirebaseCore][I-COR000006] Deleting app named __FIRAPP_DEFAULT
11.6.0 - [FirebaseCore][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://firebase.google.com/docs/ios/setup#initialize_firebase_in_your_app
11.6.0 - [FirebaseCore][I-COR000001] Configuring the default app.
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
11.6.0 - [FirebaseCrashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
If using Swift Package Manager, the project's Package.resolved
Expand Package.resolved snippet
Replace this line with the contents of your Package.resolved.
If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Thanks for reporting, @ybasset. Per checking, this seems to be an expected behavior. Crashlytics only works on Firebase default app. During initialization, we only register the Crashlytics component to default app (with the name __FIRAPP_DEFAULT). As this default app is being deleted, it is causing the issue that you're encountering. See the related code here.
I've seen that Crashlytics is tied to Firebase default app, but if we delete the Firebase default app Crashlytics shouldn't be stuck. We should be able to get Crashlytics for the newly configured Firebase default app that replaces the previous one, using the same name __FIRAPP_DEFAULT. It won't lead to multiple instances of Crashlytics since the previous one has been destroyed when deleting the Firebase app when the cache container was cleaned. Moreover the single instance check could be made on the cache container instead of an external boolean.
In my code example the second call to FirebaseApp.configure() isn't specifying the app name so it will be the new Firebase default app named __FIRAPP_DEFAULT.
Hi @ybasset, is it possible for you to provide an MCVE to reproduce the issue?
Hey @ybasset. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Hi @rizafran, sorry I'm currently on hollidays for the end of the year. I'll provide a working example when I'll be back at work.
@ybasset does Crashlytics continue to work if you hold on to the instance of Crashlytics returned by Crashlytics.crashlytics()?
Hey @ybasset. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@ybasset if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.