After I create a new swift UI project and attempt to add Firebase SDK particularly, the configuration step, the Preview doesn't work and states “failed to update preview”… review to stack overflow post above
Tbh, not sure if this is a Firebase-specific problem or XCode problem but I think it's still important if someone can look into this. After adding UIApplicationDelegate in the new swift ui app, the previews stop working. The build succeeds and the app can be ran without a hitch on a simulator, just not preview.
What happened? How can we make the problem occur?
Preview just fails
Breaking code: In your @main struct class, this is what it would look like with the new config code for Firebase using the SwiftUI:
import SwiftUI
import Firebase
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Setting up firebase")
FirebaseApp.configure()
return true
}
}
@main
struct TestApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The problem goes away but then I can't use Firebase on preview:
import SwiftUI
import Firebase
class AppDelegate: NSObject, UIApplicationDelegate {
// func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// print("Setting up firebase")
// FirebaseApp.configure()
// return true
// }
}
@main
struct TestApp: App {
// @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
I've also tried using Peter Friese's new way of configuring firebase and it still doesn't work
https://github.com/peterfriese/JewelCase/blob/main/code/JewelCase/App/JewelCaseApp.swift
I get this error:
MessageSendingError: Connection interrupted: send previewInstances message to agent
I am having the same issue:
`System Integrity Protection: enabled
Crashed Thread: 3 Dispatch queue: com.google.GDTCORFlatFileStorage
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSFileManager enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:]: URL is nil'
terminating with uncaught exception of type NSException
`
Something wrong with GoogleDataTransport/GDTCORLibrary ?
@StanfordLin I was able to get the original error message only when my GoogleService-Info.plist wasn't available.
After adding my GoogleService-Info.plist I was able to get the same error that @ppoh71 received. This was a recent change so I think there's something different in the SwiftUI Preview environment that isn't being picked up - I'll take a look and see what I can find.
Thanks for the reports!
The issue may be related to #6540. Let me take a look in more details.
The issue mentioned in the comment should be fixed by #6580.
yes, downgrading GoogleDataTransport from 7.4.0 to 7.3.0 fixes the problem
=> pod 'GoogleDataTransport', '7.3.0'
The fix #6580 is scheduled for the next release. As a temporary workaround, a previous version of GoogleDataTransport may be used (as @ppoh71 mentioned).
Thank you everyone for the information and sorry for the troubles.
@rbevans-ugh The line pod 'GoogleDataTransport', '7.3.0' should be added to the Podfile near to other Firebase pods definitions. If you use Firebase 6.33.0 this will not work unfortunately because version GoogleDataTransport 7.4 version was locked in Firebase Core podspec. In this case you may temporary lock on unreleased GoogleDataTransport version with the fix:
pod 'GoogleDataTransport', :git=>'https://github.com/firebase/firebase-ios-sdk.git', :commit=>'38be2cc'
Could you please try it and let know if you still have issues?
Thanks @maksymmalyhin. I probably should not have deleted my comment, but after some searching that's what I realized that's what I was supposed to do(new to Pods). I was also running Pod install and should have been running Pod update. Thanks for the help! After doing all this I'm back in business.
Also thanks @maksymmalyhin though I am still seeing the crash with the modified pod line while trying to preview.
Could it be related tot he app name is XCPreviewAgent.app/XCPreviewAgent but the GoogleService-Info.plist refers to my targets app name?
@aweiner42 There is some basic validation of GoogleService-Info.plist but the name mismatch should not lead to the crash.
I would suggest to get the exact crash from the Swift UI diagnostics report and update the current issue with your discovery or create a new one if the crash is in Firebase code but doesn't look related to the current issue.
To get the report you may follow the steps from the screenshot:

Then CrashLogs folder should contain recent relevant crash logs.
@maksymmalyhin thanks, I have been living in that diagnostic file trying a few things as I think I am chasing something different. for me when I try previewing a working apps controller I can't get past FirebaseApp.configure(). With the FirebaseApp.configure() I get
* Terminating app due to uncaught exception 'com.firebase.core', reason: '[FIRApp configure]; (FirebaseApp.configure() in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
terminating with uncaught exception of type NSException
abort() called
And when substitute to code in ICMSViewController below to see if it is getting the code from the bundle (which also the app runs with fine) I get the error below which leads me to think its not finding the plist in the right bundle. (so close too):
let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")!
let options = FirebaseOptions(contentsOfFile: filePath)
FirebaseApp.configure(options: options!)
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file ICMSArt_PreviewReplacement_ICMSViewController_2/ICMSViewController.swift, line 232
thanks again for any thoughts...
Most helpful comment
@rbevans-ugh The line
pod 'GoogleDataTransport', '7.3.0'should be added to thePodfilenear to other Firebase pods definitions. If you use Firebase 6.33.0 this will not work unfortunately because versionGoogleDataTransport7.4 version was locked in Firebase Core podspec. In this case you may temporary lock on unreleased GoogleDataTransport version with the fix:Could you please try it and let know if you still have issues?