firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.59k stars 1.46k forks source link

SwiftUI preview canvas crashes with manual Firebase framework install #11733

Closed mthormann-dhi closed 2 months ago

mthormann-dhi commented 1 year ago

Description

When Firebase is installed manually from zip file, includes both FirebaseAnalytics and FirebasePerformance, and then any SwiftUI file is opened with the canvas. I expected the SwiftUI view shows in preview mode. Instead the SwiftUI view briefly displays and then is replaced by the red 'x' and "Preview Crashed" message. Xcode then shows an "[app] quit unexpectedly" dialog with the option to reopen, report to Apple, or ignore.

This happens every time the canvas reloads and makes using Firebase with a manual install (which would save 30 seconds at least on build times and make many processes much faster) impossible.

This issue is essentially the same as #8005 but does not appear to be resolved with the Promises 2.3.1 distribution. I did check that FBLPromises and PromisesSwift in the 10.14.0 zip file are both on 2.3.1 but the error is still happening.

I was also chatting with @ncooke3 in #11104 about this issue as having a stable SPM binary distro would make manual zip install unnecessary.

Created with minimal reproducible example.

Crash view:

Preview crash view

Quit dialog:

Quit unexpectedly dialog

Sample crash log file: Firebase Canvas Crash Log.txt

Reproducing the issue

  1. Open Xcode and create a new iOS app.
  2. Register app with Firebase and download plist file with configuration.
  3. Add all of the Frameworks required by FirebaseAnalytics and FirebasePerformance. Note this issue does not happen which just FirebaseAnalytics installed (see screenshot)
Frameworks
  1. Add minimal code to the main app file to initialize Firebase (import Firebase and FirebaseApp.configure() in the init()). Use UIApplicationDelegate or init() makes no difference.
  2. Enable the canvas preview on the right side of the screen.

EXPECTED: SwiftUI view shows in preview mode ACTUAL: SwiftUI view briefly displays and then is replaced by the red 'x' and "Preview Crashed" message. Xcode then shows an "[app] quit unexpectedly" dialog with the option to reopen, report to Apple, or ignore.

Firebase SDK Version

10.14.0

Xcode Version

14.3.1

Installation Method

Zip

Firebase Product(s)

Analytics, Crashlytics, Performance, Remote Config

Targeted Platforms

iOS

Relevant Log Output

Incident Identifier: 4AC2E45D-A639-4043-8CC4-8A3DEB1F177B
CrashReporter Key:   1584B102-F656-58D7-0802-42A749623D01
Hardware Model:      MacBookPro18,2
Process:             FirebaseBugTest [31737]
Path:                /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/5B01915D-CE11-462B-BF74-065F72D93C43/data/Containers/Bundle/Application/6D4EABE8-C869-4768-8C1F-EE4F060656D4/FirebaseBugTest.app/FirebaseBugTest
Identifier:          com.redacted.FirebaseBugTest
Version:             1.0 (1)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [31328]
Coalition:           com.apple.CoreSimulator.SimDevice.5B01915D-CE11-462B-BF74-065F72D93C43 [7070]
Responsible Process: SimulatorTrampoline [18760]

Date/Time:           2023-08-28 11:08:44.1036 -0400
Launch Time:         2023-08-28 11:08:43.7343 -0400
OS Version:          macOS 13.5.1 (22G90)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: FirebaseBugTest [31737]

Triggered by Thread:  3

Last Exception Backtrace:
0   CoreFoundation                         0x180437324 __exceptionPreprocess + 160
1   libobjc.A.dylib                        0x180051274 objc_exception_throw + 56
2   CoreFoundation                         0x180445e3c +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                         0x18043b224 ___forwarding___ + 1308
4   CoreFoundation                         0x18043d50c _CF_forwarding_prep_0 + 92
5   FirebaseBugTest                        0x102ae2448 -[GDTCCTUploadOperation updateNextUploadTimeWithResponse:forTarget:] + 52
6   FirebaseBugTest                        0x102ae1bd0 __54-[GDTCCTUploadOperation uploadBatch:toTarget:storage:]_block_invoke + 56
7   FirebaseBugTest                        0x102af3b80 __56-[FBLPromise chainOnQueue:chainedFulfill:chainedReject:]_block_invoke.18 + 52
8   libdispatch.dylib                      0x180132ee4 _dispatch_call_block_and_release + 24
9   libdispatch.dylib                      0x180134708 _dispatch_client_callout + 16
10  libdispatch.dylib                      0x18013c95c _dispatch_lane_serial_drain + 1256
11  libdispatch.dylib                      0x18013d3dc _dispatch_lane_invoke + 392
12  libdispatch.dylib                      0x180149608 _dispatch_workloop_worker_thread + 768
13  libsystem_pthread.dylib                0x1b1834878 _pthread_wqthread + 284
14  libsystem_pthread.dylib                0x1b183363c start_wqthread + 8

Kernel Triage:
VM - (arg = 0x0) pmap_enter retried due to resource shortage

Thread 0::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x1b17dc1d0 mach_msg2_trap + 8
1   libsystem_kernel.dylib                 0x1b17ed298 mach_msg2_internal + 76
2   libsystem_kernel.dylib                 0x1b17e43d8 mach_msg_overwrite + 540
3   libsystem_kernel.dylib                 0x1b17dc540 mach_msg + 20
4   CoreFoundation                         0x18039a4a8 __CFRunLoopServiceMachPort + 156
5   CoreFoundation                         0x180394ad4 __CFRunLoopRun + 1128
6   CoreFoundation                         0x180394254 CFRunLoopRunSpecific + 584
7   GraphicsServices                       0x188eb7c9c GSEventRunModal + 160
8   UIKitCore                              0x104ddaff0 -[UIApplication _run] + 868
9   UIKitCore                              0x104ddef3c UIApplicationMain + 124
10  SwiftUI                                0x10875734c 0x107800000 + 16085836
11  SwiftUI                                0x1087571ec 0x107800000 + 16085484
12  SwiftUI                                0x107f4f474 0x107800000 + 7664756
13  FirebaseBugTest                        0x102adc430 static FirebaseBugTestApp.$main() + 40 (FirebaseBugTestApp.swift:11)
14  FirebaseBugTest                        0x102adc4d8 main + 12
15  dyld_sim                               0x102f39514 start_sim + 20
16  dyld                                   0x102fedf28 start + 2236

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json Replace this line with the contents of your Package.resolved. ```

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
```yml Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 year ago

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

ncooke3 commented 1 year ago

Thanks @mthormann-dhi, instead of configuring Firebase in the app's init, could you try implementing a UIApplicationDelegateAdaptor (https://developer.apple.com/documentation/swiftui/uiapplicationdelegateadaptor), and then calling FirebaseApp.configure() within your delegate's applicationDidFinishLaunching API?

mthormann-dhi commented 1 year ago

I've switched over to using app delegate for Firebase initialization. Most of the time, I'm still seeing it fail with the same error. Every now and then I do very occasionally get in this state where the canvas is working somehow. But if I close Xcode, and just re-open the app and re-enable previews, it just starts failing again.

Have been trying all different combinations of canvas, running the app, killing deriveddata, cleaning build folder, etc. but haven't found anything that keeps it working. Closing and re-opening Xcode always seems to cause the error to happen again regardless.

azarovalex commented 10 months ago

I see the same issue with the same setup, Firebase 10.17, FBLPromises 2.3.1 and Xcode 15.

MartinPrusa commented 10 months ago

same issue with Firebase 10.18 and Xcode 15.0.1

vahidsayad commented 6 months ago

Same issue with Firebase 10.23 and Xcode 15.3

otyvonovych commented 4 months ago

Any updates on this? Seeing the same issue with Firebase 10.25 and Xcode 15.4, however, the SDK installation method is via CocoaPods

paulb777 commented 3 months ago

We'll investigate if the planned switch to dynamic libraries in Firebase 11 makes a difference.

ncooke3 commented 2 months ago

Hi everyone, the upcoming Firebase 11 release will feature the transition from static XCFrameworks to dynamic XCFrameworks. In some pre-release testing, I was able to confirm that using dynamic XCFrameworks fixes this issue. I'm marking this as Firebase 11 is tentatively scheduled to be released later this month.

ncooke3 commented 2 months ago

Hi everyone, there have been some changes to my above comment. Firebase 11 will no longer feature the transition to dynamic XCFrameworks. This is due to Swift Package Manager not being able to support dynamic binary targets that depend on source targets.

That being said, we identified an alternative fix for this issue that will be coming in Firebase 11.0.0.

mthormann-dhi commented 2 months ago

@ncooke3 Should this be re-opened in that case so it doesn't fall through the cracks? Or is that already verified as fixed in 11.0?

ncooke3 commented 2 months ago

Hi @mthormann-dhi, this should be fixed in the 11.0.0 Firebase.zip.