Crash Xcode 13.4 swift::fatalError Xcodebuild

Lately we have added swift code to our SDK. (especially swiftUI library). The SDK deployment target is ios9.

While importing the SDK to the hosting app with the same deployment target and building via Xcode (13.4) everything works fine.

When we try to build it via xcodebuild (xcodebuild -workspace UIKitCatalog.xcworkspace -scheme UIKitCatalog -sdk "iphonesimulator") the build is done successfully but the the app is crashing on app lunch (sim and device) . Increasing the deployment target of the hosting app to iOS 13 fixes the issue (unfortunately we cant force our customers to do the same)

CrashReporter Key:   74B25560-EFCE-769F-F0B4-E4DD4C6B09A4
Hardware Model:      MacBookPro15,1
Process:             UIKitCatalog [63980]
Path:                /Users/USER/Library/Developer/CoreSimulator/Devices/F044CBD3-80D6-49FB-BAC9-FA48FA3CFF7E/data/Containers/Bundle/Application/72290230-2DB3-4F75-8327-75B6E4E9947C/UIKitCatalog.app/UIKitCatalog
Identifier:         ba.UIKitCatalog
Version:             2.0.0.23386 (23386)
Code Type:           X86-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [56632]
Coalition:           com.apple.CoreSimulator.SimDevice.F044CBD3-80D6-49FB-BAC9-FA48FA3CFF7E [10638]
Responsible Process: SimulatorTrampoline [2048]

Date/Time:           2022-08-29 11:59:21.3026 +0300
Launch Time:         2022-08-29 11:59:19.9381 +0300
OS Version:          macOS 12.5.1 (21G83)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	    0x7fff7017300e __pthread_kill + 10
1   libsystem_pthread.dylib       	    0x7fff701cb1ff pthread_kill + 263
2   libsystem_c.dylib             	    0x7fff2010b6b7 abort + 130
3   libswiftCore.dylib            	       0x10e7c0af5 swift::fatalError(unsigned int, char const*, ...) + 149
4   libswiftCore.dylib            	       0x10e7b86ec checkVersion() + 44
5   dyld_sim                      	       0x10d0689f7 invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 182
6   dyld_sim                      	       0x10d0850f5 invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 129
7   dyld_sim                      	       0x10d07e58c invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 555
8   dyld_sim                      	       0x10d07d6e9 dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 129
9   dyld_sim                      	       0x10d07e31f dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 179
10  dyld_sim                      	       0x10d084b56 dyld3::MachOAnalyzer::forEachInitializerPointerSection(Diagnostics&, void (unsigned int, unsigned int, unsigned char const*, bool&) block_pointer) const + 118
11  dyld_sim                      	       0x10d084d98 dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 386
12  dyld_sim                      	       0x10d06892a dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 144
13  dyld_sim                      	       0x10d068ac2 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 190
14  dyld_sim                      	       0x10d068aa5 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 161
15  dyld_sim                      	       0x10d068aa5 dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 161
16  dyld_sim                      	       0x10d068b60 dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 102
17  dyld_sim                      	       0x10d077b5a dyld4::APIs::runAllInitializersForMain() + 222
18  dyld_sim                      	       0x10d05b9fe dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 2528
19  dyld_sim                      	       0x10d05be42 _dyld_sim_prepare + 379
20  dyld                          	       0x110e6eb78 dyld4::prepareSim(dyld4::RuntimeState&, char const*) + 1265
21  dyld                          	       0x110e6d70e dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 244
22  dyld                          	       0x110e6d4e4 start + 388

How can we overcome this issue?

What Xcode is doing under the hood that xcodebuild doesnt do?

Is it possible to release an SDK which import swiftUI but will have deployment target lower than 13. (I have wrapped all the the swift code with @available() and #if canImport(SwiftUI) - less relevant as its compile time )

is there any update on this? facing the same issue....

Any solution for this? Facing the same issue and not sure how to debug it without further information and am unable to reproduce the issue locally.

This suggests that your project has a problem with its dynamic linker rpath configuration. Something similar recently came up in a DTS incident I was working on, so I decided to write up my explanation. Start with Dynamic Library Identification and then follow the link to Dynamic Library Standard Setup for Apps and its Swift System Libraries section.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Crash Xcode 13.4 swift::fatalError Xcodebuild
 
 
Q