Library Not Found issue When Running on an iOS Device Using Swift Package Manager

Q: I am using Swift Package Manager, and I am getting the following “Library Not Found” issue when launching my app on a real iOS Device:

Copy
1
2
3
4
5
6
7
dyld: Library not loaded: @rpath/PSPDFKit.framework/PSPDFKit
  Referenced from: /private/var/containers/Bundle/Application/ED1962E0-BA44-463B-B22C-2AB0447F9C13/Catalog.app/Catalog
  Reason: no suitable image found.  Did find:
	/private/var/containers/Bundle/Application/ED1962E0-BA44-463B-B22C-2AB0447F9C13/Catalog.app/Frameworks/PSPDFKit.framework/PSPDFKit: code signature in (/private/var/containers/Bundle/Application/ED1962E0-BA44-463B-B22C-2AB0447F9C13/Catalog.app/Frameworks/PSPDFKit.framework/PSPDFKit) not valid for use in process using Library Validation: mapping process and mapped file (non-platform) have different Team IDs
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

A: This occurs because Xcode fails to sign the frameworks that are provided by SwiftPM with your app’s signing identity. It’s a known issue (SR-13343) in Xcode 12.

To work around this issue, please follow the steps below:

  1. Add a new copy files phase in your application’s Build Phase:
  2. Change the copy files phase’s destination to Frameworks:
  3. Add a new run script phase script to your app’s target:
  4. Add the following script to force deep sign the frameworks with your own signing identity:
Copy
1
2
3
4
find "${CODESIGNING_FOLDER_PATH}" -name '*.framework' -print0 | while read -d $'\0' framework 
do 
    codesign --force --deep --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements --timestamp=none "${framework}" 
done

Your target’s build phases should look like this: