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

大城市里の小女人 提交于 2020-03-17 10:40:10

问题


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?


回答1:


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



回答2:


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?




回答3:


Deleting old developer certificates from Keychain Access helped for me.




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/46747801/dyld-library-not-loaded-rpath-libswiftavfoundation-dylib-reason-image-not-fo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!