Crash on launch when adding a Swift package with a binary target

I have compiled Google's WebRTC library and bundled up everything into xcframework in order to distribute as a binary framework in Swift package manager.

When I add the package to my project it compiles and runs on a simulator. However, on a physical device, it crashes on launch with the following error:

dyld: Library not loaded: @rpath/WebRTC.framework/WebRTC
Referenced from: /private/var/containers/Bundle/Application/AA9F8C9C-7EF4-4556-8848-1EEFE1785658/WebRTC-Demo.app/WebRTC-Demo
Reason: image not found
dyld: launch, loading dependent libraries
DYLDLIBRARYPATH=/usr/lib/system/introspection
DYLDINSERTLIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Further investigation:

  • After archiving the project and exporting ipa file, the ipa file is missing the binary framework and still crashing on launch.

  • Removing the Swift package and attaching the xcframework manually (by drag and drop) works on Simulators and physical devices.


Tech specs

  • XCFramework created on macOS 10.15.5 with Xcode 11.5

  • Used Xcode 12.0 beta 1 on macOS 10.15 for the app which uses the framework.

  • I got the error above on iPhone X and iPad pro 10.5"

  • Used the following Package.swift file.

  • Framework download link can be found in the Package.Swift file above.


Any suggestions/insights would be helpful.

Thanks!

Accepted Reply

The issue has been fixed in one of the recent Xcode 12.x releases (not sure which exactly, maybe 12.1)

Replies

Hi @stasel,

Any luck on solving this? I'm running into the same issue. There is unfortunately no option under the "Embed" column within the "General" tab > "Frameworks, Libraries, and Embedded Content" to "Embed and Sign" and/or "Embed without Signing" as is available with source-compiled packages that are added to the app target. Drag-and-drop works, but the absolute path is hardcoded to the build location under the DerivedData folder so the changes cannot be used outside of my machine.

Thanks!
Does anyone have any updates on this? This is currently a blocker for us in migrating from CocoaPods over to SwiftPM. Thanks.
Still having this issue on Xcode 12 beta 3
Opened a feedback ticket - FB8137382

Anyone else experiencing this issue on other binary frameworks (Other than WebRTC framework I mentioned)?
There appear to be multiple issues still with binaryTarget support in SPM.

I've run into this exact issue with multiple dynamic xcframeworks. I filed a bug with reproducible test case at: https://bugs.swift.org/browse/SR-13345.

I can make static xcframeworks that will launch properly though, however they also have an issue. If I embed another framework/xcframework (dynamic) directly into the application and link a binaryTarget static xcframework via SPM, then the application will not codesign properly when trying to run on a device. This has a bug report and test case at: https://bugs.swift.org/browse/SR-13343

So unfortunately I don't have a solution for you, but I can confirm that it probably isn't your xcframework specifically.

Hi opi-smccoole, Thanks for the heads up! Agreed, code signing is where things get tricky. Thank you for filing those issues and fingers crossed they get addressed in a timely manner. 🤞
Still experiencing this in Xcode 12 Beta 5.
I have the exact same issue. works great on simulator crashes on device

Code Block
dyld: Library not loaded: @rpath/MyFramework.framework/MyFramework
  Referenced from: /private/var/containers/Bundle/Application/0CD0A16D-5C76-479D-83FE-4785E96E809C/TestSPM.app/TestSPM
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

We have the same issue. It's hard to imagine there isn't a fix for this, now that they've gone to the GM Seed with Xcode 12 and iOS 14.
I have the exact same issue with Xcode 12.0 beta 6.
Please Apple give us some answer.

Code Block
dyld: Library not loaded: @rpath/MyFramework.framework/MyFramework
  Referenced from: /private/var/containers/Bundle/Application/59D35023-446B-4EDC-8885-D981C9FA8CFA/SPM Demo.app/SPM Demo
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Made some odd progress when working on this myself. I have a SPM with a XCFramework as a binary target. I decided to go off the beaten path and manually sign it anyways even though it's a local binary rather than remote binary. Dyld made it past the linker phase, recognized the checksum generated by Swift per the docs, and failed with the following output in the console.

Code Block
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Why it died while loading the debugger library I have no earthly idea. My dependency is nested in a dynamic library so I'm interested as to the outcome manually signing a local binary will have for anyone else. It's not hard to override. Show the package in finder from Xcode. Zip your binary. Follow the docs instructions on deriving the checksum for a remote binary. Unlock the Package.swift file, add the checksum field to the binary target as though it's remote. Clean, build, run. It makes it past the checksum and fails at loading the debugger for me. Hopefully for others it does not.

Obviously this is not an ideal outcome but I'm searching for a workaround because I would very much like to kill the last of my Carthage dependencies in favor of a SPM dependency graph.
Still seeing in Xcode 12.0.1. Tried adding SwiftUI as an explicit dependency marked 'Do Not Embed', but see the same.

Code Block shell
dyld: Symbol not found: _$s7SwiftUI12ProgressViewVyxq_GAA0D0AAMc
  Referenced from: /private/var/containers/Bundle/Application/E9FB9FBD-F564-4236-B208-84CC14E96629/SwiftUIStylingProto.app/SwiftUIStylingProto
  Expected in: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
 in /private/var/containers/Bundle/Application/E9FB9FBD-F564-4236-B208-84CC14E96629/SwiftUIStylingProto.app/SwiftUIStylingProto
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Any update on this issue? how to fix it?
The issue has been fixed in one of the recent Xcode 12.x releases (not sure which exactly, maybe 12.1)
 Referenced from: /Users/yashjadhav/Library/Developer/CoreSimulator/Devices/4D5231BB-420A-428A-B2C4-E8EC4EF59DEE/data/Containers/Bundle/Application/D748881B-FB1E-48BD-AFDF-C953A1BD7226/DemoTen.app/Frameworks/SafexPay.framework/SafexPay
 Reason: no suitable image found. Did find:
	/Users/yashjadhav/Library/Developer/CoreSimulator/Devices/4D5231BB-420A-428A-B2C4-E8EC4EF59DEE/data/Containers/Bundle/Application/D748881B-FB1E-48BD-AFDF-C953A1BD7226/DemoTen.app/Frameworks/SafexPay.framework/Frameworks/IQKeyboardManagerSwift.framework/IQKeyboardManagerSwift: no matching architecture in universal wrapper
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/yashjadhav/Library/Developer/CoreSimulator/Caches/dyld/20F71/com.apple.CoreSimulator.SimRuntime.iOS-14-5.18E182
DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/yashjadhav/Library/Developer/Xcode/DerivedData/DemoTen-fhhoqxdqnnnppffmbqyfyyabwfrf/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/Co

Getting this issue When running on Simulator but it runs very well in device What could be the issue ?

Using Xcode 12.5.1

I have same issue with XCode Version 13.2.1 (13C100) on simulator, works well on device. Any workaround helps ((