Hello all,
There's a really frustrating crash with Xcode Previews because it cannot find the design resources package using the Bundle.module
accessor (filed FB9479423). Is there something wrong with the package setup?
I have some Swift packages dependent on another package containing design resources. Xcode Previews do not work because XCPreviewAgent crashes:
CompanyDesign/resource_bundle_accessor.swift:27: Fatal error: unable to find bundle named CompanyDesign_CompanyDesign
Is there some other way packages should be locating their resources, rather than relying on the Bundle.module
static property?
Others have been having this issue too. Here's a sample GitHub repo I found.
Our current work around is to build and run a new Xcode app project that includes the package as a dependency, builds the library target and uses the library API in the Simulator (Xcode Previews are a bit hit and miss in this case). But it's a really messy solution requiring us to keep unrelated Xcode projects up to date and working properly.
Any ideas?
Crash log
Process: XCPreviewAgent [60209]
Path: /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/4187DDA6-B83B-4A6D-9A63-8BA6E5C73BA2/data/Containers/Bundle/Application/9CE529F9-E954-4303-9BD2-3A04C779C291/XCPreviewAgent.app/XCPreviewAgent
Identifier: XCPreviewAgent
Version: 13.0 (19073)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [59987]
Responsible: SimulatorTrampoline [59322]
User ID: 501
Date/Time: 2021-08-10 10:39:26.062 +1000
OS Version: macOS 11.5.1 (20G80)
Report Version: 12
Bridge OS Version: 5.5 (18P4759a)
Anonymous UUID: EA6339C9-99B4-FD37-88E1-77676FE83B62
Sleep/Wake UUID: 112E14C2-9BD3-4D1C-BD53-8D0843C3E188
Time Awake Since Boot: 130000 seconds
Time Since Wake: 90000 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: exc handler [60209]
Application Specific Information:
dyld4 config: DYLD_ROOT_PATH=/Users/kgillard/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/kgillard/Library/Developer/Xcode/DerivedData/CompanyPeopleList-euiaatprplkzjxhdopirqrpyuzvg/Build/Intermediates.noindex/Previews/CompanyPeopleList/Products/Debug-iphonesimulator DYLD_INSERT_LIBRARIES=/Users/kgillard/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot//System/Library/PrivateFrameworks/XCPreviewKit.framework/XCPreviewKit DYLD_FRAMEWORK_PATH=/Users/kgillard/Library/Developer/Xcode/DerivedData/CompanyPeopleList-euiaatprplkzjxhdopirqrpyuzvg/Build/Intermediates.noindex/Previews/CompanyPeopleList/Products/Debug-iphonesimulator
CompanyDesign/resource_bundle_accessor.swift:27: Fatal error: unable to find bundle named CompanyDesign_CompanyDesign
CoreSimulator 775 - Device: iPhone 12 (4187DDA6-B83B-4A6D-9A63-8BA6E5C73BA2) - Runtime: iOS 15.0 (19A5307d) - DeviceType: iPhone 12
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x0000000106b482db _assertionFailure(_:_:file:line:flags:) + 427
1 CompanyPeopleList 0x000000012f673766 closure #1 in variable initialization expression of static NSBundle.module + 2102
2 CompanyPeopleList 0x000000012f672f19 one-time initialization function for module + 9
3 libdispatch.dylib 0x000000010bf32c89 _dispatch_client_callout + 8
4 libdispatch.dylib 0x000000010bf33ed8 _dispatch_once_callout + 20
5 CompanyPeopleList 0x000000012f673941 NSBundle.module.unsafeMutableAddressor + 49
6 CompanyPeopleList 0x000000012f6abc2b CompanyImage.safeSwiftUIImage.getter + 955
7 CompanyPeopleList 0x000000012f6ab6be CompanyImage.swiftUIImage.getter + 142
8 PeopleListView.2.preview-thunk.dylib 0x0000000129529f2d closure #2 in closure #2 in closure #1 in CompanyPeopleListView.__preview__body.getter + 189
9 com.apple.SwiftUI 0x0000000108760d0e Button.init(action:label:) + 70
10 PeopleListView.2.preview-thunk.dylib 0x0000000129529b9d closure #2 in closure #1 in CompanyPeopleListView.__preview__body.getter + 525
11 PeopleListView.2.preview-thunk.dylib 0x000000012952a8e1 partial apply for closure #2 in closure #1 in CompanyPeopleListView.__preview__body.getter + 17
12 com.apple.SwiftUI 0x0000000108634c1f HStack.init(alignment:spacing:content:) + 159
13 PeopleListView.2.preview-thunk.dylib 0x0000000129528181 closure #1 in CompanyPeopleListView.__preview__body.getter + 1201
14 PeopleListView.2.preview-thunk.dylib 0x0000000129528631 partial apply for closure #1 in CompanyPeopleListView.__preview__body.getter + 17
15 com.apple.SwiftUI 0x0000000107f16cfb NavigationView.init(content:) + 48
16 PeopleListView.2.preview-thunk.dylib 0x0000000129527b6e CompanyPeopleListView.__preview__body.getter + 606
17 CompanyPeopleList 0x000000012f651efe CompanyPeopleListView.body.getter + 142
18 CompanyPeopleList 0x000000012f654dc1 protocol witness for View.body.getter in conformance CompanyPeopleListView + 17
19 com.apple.SwiftUI 0x0000000107eda535 partial apply for closure #1 in ViewBodyAccessor.updateBody(of:changed:) + 22
...
...
...```