13

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?

drewster
  • 5,460
  • 5
  • 40
  • 50

5 Answers5

24

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
drewster
  • 5,460
  • 5
  • 40
  • 50
  • This helped.. All bullshit of deleting here and there was not a solution! – Kasnady Feb 06 '18 at 09:58
  • Btw,, i got error of Symbol not found:.. what to do with that.. did you know about it? – Kasnady Feb 06 '18 at 11:02
  • SYMBOL not found? - might be a different issue. Maybe start a new question. – drewster Feb 07 '18 at 19:20
  • 2
    Thanks for your reply @drewster, I had found out the problem. It was actually Swift Compiler issue which not related to this. So it was solved.. – Kasnady Feb 08 '18 at 02:29
  • @drewster and Kasnady could you please help me to navigate to your home folder/swiftStdLib ? I really really need your help. I can't find folder/swiftStdLib :( . here is the pic https://i.stack.imgur.com/qoUri.png – Alexa289 Apr 12 '18 at 03:58
  • @Alexa289 in your screenshot it would be /Users/yourname/swiftStdLib - that is AFTER you run the commands above. – drewster Apr 12 '18 at 16:56
  • I try do that now i catch: Invalid Swift Support - The SwiftSupport folder is empty – Bimawa Apr 27 '18 at 16:02
  • 2
    Excellent, saved my day! Thanks :) – cujo30227 Sep 18 '18 at 21:05
  • @Kasnady hello, I am getting the same error msg like you 'Symbol not found'. How did you solve that problem please? (in Xcode 9.2, iOS 12 iPhone 6s.) – KoreanXcodeWorker Sep 28 '18 at 06:23
  • when I run cp command I get,,, zsh: no matches found: libswift*.dylib ,, any idea?? – Amol Gangadhare Nov 28 '19 at 11:54
  • @AmolGangadhare The Swift libraries folder has been renamed to include the Swift version number. So for example, in Xcode 11.3, instead of one of the subfolders in the path being named 'swift', it's now named 'swift-5.0'. Take a look at the updated answer. – drewster Dec 15 '19 at 16:31
  • I am getting error against every library that I added like this -- "Building for iOS Simulator, but the linked and embedded library '***.dylib' was built for iOS.". Please that I am using Xcode 11.3 – Basir Alam Apr 26 '20 at 23:30
4

Before adding frameworks try this:

I deleted derived data in xcode9 - it works for me

refer link below: How to delete contents from derived data

How can I delete derived data in Xcode 9?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ioSana
  • 117
  • 2
  • Deleting the app from the phone, then deleting derived data and trying to build to device again resolved it for me. – Senseful Aug 22 '18 at 14:19
0

Deleting old developer certificates from Keychain Access helped for me.

Denis
  • 89
  • 4
0

Just cleaning the project sometimes seems to work for me. I have noticed this happen more frequently when I have a swfit/objc/c++ project combination.

nnrales
  • 1,481
  • 1
  • 17
  • 26
-1

Simple step to follow

Project -> Build Phases -> Embed Frameworks -> +.

It will works for all.. Perfect solution for everyone.

  • Add library in Link Binary with Libraries &
  • Add new Copy Files Phrase, Select framework in destination section and import library there.
  • And Run your code.. Magic.. Enjoy

NOTE:-Please make sure "Copy only when installing" in Copy files is unchecked

enter image description here

Community
  • 1
  • 1
Mehul
  • 3,033
  • 23
  • 37