Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib Reason: image not found

I'm getting this error upon launch of my app. I am building under Xcode 9.0 (9A235) on MacOS High Sierra 10.13. I also tried building under Xcode 8.3.3 with the same result. The project is generally Objective C, but the framework YouAppi.framework is Swift:

dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib
  Referenced from: /private/var/containers/Bundle/Application/7D3E2815-4CA3-4258-AEF6-C0626055A8F2/dingbats.app/Frameworks/YouAppi.framework/YouAppi
  Reason: image not found

At first glance, this appears to be a duplicate of this question, but the error is different in that one. In that other question, the Reason is no suitable image found, where mine is image not found.

I've tried the following to resolve:

  1. Remove and re-add the framework
  2. Clean and Option+Clean the project
  3. Delete ~/Library/Developer/Xcode/DerivedData folder
  4. Build Settings -> Always Embed Swift Standard Libraries = Yes
  5. Build Settings -> Strip Swift Symbols = No
  6. Build Settings -> Linking -> Runpath Search Paths --
    • added @loader_path
    • added @rpath
    • added @executable_path/Frameworks
  7. Checked developer and distribution certificates that Trust was set to Use System Defaults
  8. Checked that I have latest WWDR and G2 certificates installed
  9. Checked validity of above-mentioned certificates
  10. Moved YouAppi.framework into Frameworks/ folder. (It was originally in a "Third-Party Frameworks" folder.)
  11. Tried copying libswiftAVFoundation.dylib into my project's Frameworks folder

I haven't moved to a new computer recently.

I have the same result on my iPhone 7+ running iOS 11.0.23 (15A432) as well as an iPad Mini 1 running iOS 9.3.5 (13G36).

Also tried this:

rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode

Ideas?

like image 582
drewster Avatar asked Oct 14 '17 18:10

drewster


1 Answers

When including a framework built with Swift in a non-Swift project, the Swift standard libraries need to be copied into the final output. Xcode has a checkbox for this (#4 in the original question), but apparently there's a bug where, in some cases, it doesn't actually happen.

I saw another thread somewhere that said this happens when you have a framework built with Swift, which is built for multiple architectures, such as armv7 and arm64. (See the thread here.)

In any case, the solution is to add them all manually. The files you are looking for are in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos.

What I did was this:

Step 1. Open Terminal and type this, copying the libraries to a new folder, swiftStdLib, in your home directory.

cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib

Step 2. Within Xcode, go to General -> Embedded Binaries, and hit the + to add. Click Add Other, then navigate to your home folder/swiftStdLib. Select all and hit enter.

Step 3. Clean and build the project.

Hope this helps someone.

UPDATE FOR XCODE 11:

In Xcode 11.3, the Swift libraries folder has changed to include the major Swift version number. The original question was based on Xcode 9, so this probably changed earlier than Xcode 11.3, but I haven't checked.

The new folder is /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos.

So that makes Step 1, above, this instead:

cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib
like image 82
drewster Avatar answered Sep 21 '22 08:09

drewster