dyld: Library not loaded: #rpath/libswiftContacts.dylib - xcode

dyld: Library not loaded: #rpath/libswift_stdlib_core.dylib
dyld: Library not loaded: #rpath/libswiftCore.dylib. Issue persist
I know that theses question have been answered several times, but "dyld: Library not loaded: #rpath/libswiftContacts.dylib" I have not been able to find a proper solution to this error when I am coding a Swift
application for XCode 7.2:
Here I use Contact & ContactUI Frameworks:: #rpath/libswiftContacts.dylib
dyld: Library not loaded: #rpath/libswiftContacts.dylib
Referenced from: /var/mobile/Containers/Bundle/Application/C0F2B5CB-628C-4643-9473-648D3099D8FB/HomeMadeFood_User.app/HomeMadeFood_User
Reason: image not found
I have tried all these actions:
Restarting Xcode, iPhone, computer
Cleaning & rebuilding
Revoking and creating new certificate/provision profile
Runpath Search Paths is '$(inherited) #executable_path/Frameworks'
Embedded Content Contains Swift Code is 'Yes'
Code Signing Identity is developer
deleting Xcode's Derived Data directory.
but I have always got the same error...
I tried like this: but i am getting an error like:
/Users/mac-jarc/Library/Developer/Xcode/DerivedData/HomeMadeFood_User-bmwdevsopruaqxfrbibhaspidobn/Build/Products/Debug- iphoneos/HomeMadeFood_User.app/Frameworks/Contacts.framework: bundle format unrecognized, invalid, or unsuitable
Command /usr/bin/codesign failed with exit code 1

I had this same error for a couple of weeks:
dyld: Library not loaded: #rpath/libswiftContacts.dylib
Basically I was able to run and test my app on device. Then about 2 weeks ago, I wasn't able to run the tests on device anymore. Tests were running fine on simulator. I can't think what changed. The error I saw was the one above. I searched Google for ages trying to find a solution, and tried many fixes unsuccessfully. The fix that finally worked was to delete the Derived Data. Once I did this, I was once again able to run the tests on my device.
Fix that worked for me:
Go to Xcode > Preferences > Locations > Derived Data (click on little arrow to open up the folder in finder)
e.g. /Users/[username]/Library/Developer/Xcode/DerivedData
Delete the entire DerivedData folder
Clean/Build
Test on device - finally works again

In our case, it was clear that there was a bug in the way Xcode was resolving dependencies to our target.
Let's me start by saying, the solution was:
import PassKit
Now, before you raise that eyebrow, here is why this worked:
We relied on a Swift framework that imports PassKit
We distributed the prebuilt binary to team members
The team observed the crash, just as OP mentioned it
Adding that import in the app target made Xcode embed the required swift libraries
Note: Just linking PassKit in the GUI did absolutely nothing.

Cracked it.
Check if the framework you're trying to build or one of it's dependency framework uses any of the Swift standard libraries. If yes, create a NEW key in the build settings
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;

This error is caused due to invalid certification of Apple.
Go to your keychain access. Under "Keychains" select "System" and under "Category" select "Certificates". Check whether the "Apple Worldwide Developer Relations Certification Authority" is valid or not. If not download that certificate from Apple site. It'll solve the problem.

I know this is old question, but this is what helped me
Speaking shortly:
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES

Related

Why do I have to embed my libraries inside my applications binary for them to work?

So I followed this tutorial:
http://locomoviles.com/ios-tutorials/create-ios-cocoa-touch-framework-using-xcode/
Everything went fine except when I went to run the program I got the following error:
> dyld: Library not loaded:
> #rpath/SwiftFramework.framework/SwiftFramework Referenced from:
> /Users/bluke/Library/Developer/CoreSimulator/Devices/40677D10-F22B-4AE4-B767-06439AB7887A/data/Containers/Bundle/Application/8C6A5F76-C666-4B69-9353-A0ABD7DA085B/UseFramework.app/UseFramework
> Reason: image not found
I was able to solve this problem by adding the framework as an embedded binary, but I don't understand why this was needed to solve the problem.
I thought that the framework would be included in my application bundle as a dynamically linked library (i.e. not embedded in my application's binary directly) and then linked at run time. Is this assumption incorrect?
Just in case my question was unclear, I've added the following pictures.
This is what was producing the error:
If I add the framework to the embedded binaries it works:
I thought that the framework would be included in my application
bundle as a dynamically linked library (i.e. not embedded in my
application's binary directly) and then linked at run time. Is this
assumption incorrect?
Yes, it's incorrect. iOS apps link 3rd party frameworks statically, not dynamically. This prevents apps from downloading and dynamically linking code that hasn't been vetted by the app store review process.
This allows apps coded in Swift to run on devices running a version of iOS pre-dating Swift (earlier than iOS8).
Non-Apple frameworks can be embedded on iOS8 and above only.
It is also nice to add a prefix the the name identifying the developer organization so as to avoid comflicts and confusion. "SwiftFramework" looks so much like an Apple framework.

MacOSX screensaver not loading due to Library not loaded: #rpath/libswiftAppKit.dylib

We have a working Mac OS X screensaver as a standalone Xcode project, but we needed to have it as a target in another Xcode project that also contains a related app.
I added a target for a screensaver, copied the code, added to that target, etc, etc. The code is the same one that works in the other screensaver, but on this one, it generates the following error:
2015-03-10 09:43:24.766 System Preferences[32495]: Error loading /Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja: dlopen(/Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja, 265): Library not loaded: #rpath/libswiftAppKit.dylib
Referenced from: /Users/pupeno/Library/Screen Savers/Ninja.saver/Contents/MacOS/Ninja
Reason: image not found
2015-03-10 09:43:24.766 System Preferences[32495]: ScreenSaverModules: can't get principalClass for /Users/pupeno/Library/Screen Savers/Ninja.saver
The library in question is definitely there:
$ ls -w1 Library/Screen\ Savers/Ninja.saver/Contents/Frameworks/
libswiftAppKit.dylib
libswiftCore.dylib
libswiftCoreGraphics.dylib
libswiftDarwin.dylib
libswiftDispatch.dylib
libswiftFoundation.dylib
libswiftObjectiveC.dylib
libswiftQuartzCore.dylib
libswiftSecurity.dylib
Any ideas what might be causing this?
The problem was that the Runpath Search Path, for some reason, in this new target, was blank. I fixed this problem by adding this:
#executable_path/../Frameworks #loader_path/../Frameworks
to it (which I took from the working screensaver configuration). This is how it looks like:
Like Pablo said, you need the following as your Runtime Search Path:
#executable_path/../Frameworks #loader_path/../Frameworks
This should be the default. Make sure it's there though. You also need to set Embedded Content Contains Swift Code to YES if you're using Swift. That took me awhile to figure out.
(Xcode should totally infer this. Oh well. I filed a radar for this awhile.)

How to use libclang in Xcode

I want to use the libclang library included with Xcode to do some simple source code parsing.
This is how I do it.
Figure out the libclang.dylib using echoxcode-select --print-path/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
Copy the libclang.dylib file to my project folder.
Add it to a clean Xcode project (a Cocoa Application one).
Build and run the app
The built process runs fine but the app crash on start up with this error
dyld: Library not loaded: #rpath/libclang.dylib
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/ClassStructureAnalyzer-cthpbscauprydagysmerutpnhpua/Build/Products/Debug/ClassStructureAnalyzer.app/Contents/MacOS/ClassStructureAnalyzer
Reason: image not found
Adding the /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib to the runpath doesn't solve the problem.
I understand that this question may have been asked many times, but after googling for the whole day, I haven't figure out the answer yet :(
Thanks in advance!

OS X Framework Library not loaded: 'Image not found'

I am trying to create a basic OS X Framework, right now I just have a test framework created: TestMacFramework.framework and I'm trying to import it into a brand new OS X Application project.
I have built the .framework file and imported it into the new project, The framework appears to link okay, and I can reference the public header file I added to the framework build phases section.
However, when I try to run the container Application I get the following Error:
dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
Reason: image not found
After a bit of googling I realised I needed to add a Copy Files section to my container application build phases, so I have done this and set it up like so...
However, I am still getting the runtime error. I'm obviously doing something wrong here, but the Apple developer library resource for this references Xcode 2, so isn't very helpful!
What have I missed?
UPDATE:
I can see in the build log that my TestMacFramework.framework is being copied into the .app contents/frameworks directory, but it isn't being installed to the Library/Frameworks directory on the HD
UPDATE 2:
The build links correctly if I manually copy the TestMacFramework.framework into the Library/Frameworks directory
[Xcode 11+]
The only thing to do is to add the framework to the General->Frameworks, Libraries And Embedded Content section in the General tab of your app target.
Make sure you select the 'Embed & Sign' option.
[Xcode v6 -> Xcode v10]
The only thing to do is to add the framework to the Embedded binaries section in the General tab of your app target.
So I managed to get it working, it's quite simple when you have the right instructions. What I was looking for was a 'private' framework which lives in the App bundle rather than being written to the system library folder.
Building The Framework
Add a target to create a Cocoa Framework
Within that targets 'Build Settings' configure the 'Installation Directory' to '#executable_path/../Frameworks'
Build library, and access the .framework from the archive or products directory
Including The Framework
Drag the created .framework file into the Xcode Project, be sure to tick 'Copy Files to Directory'
In the containing applications target, add a new 'Copy File Build Phase'
Set the 'Destination' to 'Frameworks'
Drag in the created .framework
It was quite simple for me, i just added my framework to my embedded binaries under app targets
The options above where not possible for me to include.
I solved it by specifying the Runpath Search Path
This is on the 'Build Settings' tab.
In the 'Linking' section.
Change 'Runpath Search Paths' into $(inherited) #executable_path/Frameworks
I ran into the same issue but the accepted solution did not work for me. Instead the solution was to modify the framework's install name.
The error in the original post is:
dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
Reason: image not found
Note the first path after Library not loaded. The framework is being loaded from an absolute path. This path comes from the framework's install name (sometimes called rpath), which can be examined using:
otool -D MyFramework.framework/MyFramework
When a framework is embedded into an app this path should be relative and of this form: #rpath/MyFramework.framework/MyFramework. If your framework's install name is an absolute path it may not be loaded at runtime and an error similar to the one above will be produced.
The solution is to modify the install name:
install_name_tool -id "#rpath/MyFramework.framework/MyFramework" MyFramework.framework/MyFramework
With this change I no longer get the error
Deleting derived data saved it for me
None of these issues solved this for me. The problem in the end was pretty easy. It looks like its a pretty major Xcode bug which I have logged the problem and fix under Apple bug: 29820370. If you are struggling (as it seems like there are several pages of problems similar to this ) then it would be great if you can raise a bug on bug reporter: https://bugreport.apple.com/ and reference the bug I raised to gain visibility. I want to make Xcode back into the pleasure that it was before - and this is something I am sure Xcode should have fixed itself.
Here is the fix:
1. Open Keychain - go to Apple Worldwide Developer Cert.
2. Double Click on it
3. Change the permission level from "always trust" to use System Defaults
4. Save and close it
5. Restart Xcode, Clean and build your project and it should be gone.
Screenshot below of the correct settings:
Hope this helps!
When you drag a custom framework into a project under Xcode 10.1, it assumes that the framework is a system framework and puts the framework into "Link Binary With Libraries" section of "Build Phases" under your target.
System frameworks are already on the device so it is not copied over to the device and thus cannot execute at runtime so KABOOM (crash in __abort_with_payload, and disinforming error: "Reason: image not found"). This is because the framework code is not copied to the device...
In reality, to have Xcode both link the custom framework and ensure that it is copied along with your code to the iOS device (real or simulator) the custom framework needs to be moved to "Copy Bundle Resources". This ultimately packages the framework along with your code executable to be available on the device together.
To add a custom framework to a project and avoid the Apple crash:
Drag custom framework into your iOS project file list
Click ProjectName in Navigator -> TargetName -> "Build Phases" ->
Link Binary With Libraries disclosure triangle
Drag custom framework out and down to "Copy Bundle Resources" section below (Xcode now moves the framework reference, fixed in Xcode 10)
Run in simulator or device
The custom framework thus gets copied along with your code to your target device and is available at runtime.
[editorial: you would think Xcode would be smart enough to figure out the difference between one of it's system frameworks which need not be copied to the device and a custom framework that is, oh I don't know, in the project root directory hierarchy... 🙄]
Xcode 11 :
in Xcode 11 add framework into General->Frameworks, Libraries And Embedded Content
after adding make sure you select Embed & Sign option
There should be a 'Run Script' into 'Build Phases' with this: '/usr/local/bin/carthage copy-frameworks'
On the 'Input Files' of that 'Run Script', you should add the path to your libraries. Like this:
If you accidentally reset your keychain, this can occur due to missing Apple certificates in the keychain. I followed this to solve my problem.
I had the same issue and was able to fix by re-downloading the WWDR (Apple Worldwide Developer Relations Certification Authority).
Download from here: http://developer.apple.com/certificationauthority/AppleWWDRCA.cer
If you are using Xcode 11, ensure that you have the framework added in Frameworks, Libraries, and Embed Content under Target settings - General. Change Embed status from - 'Do not Embed' to 'Embed & Sign'
What solved it for me was changing abstract_target to target for the main target in my Podfile. I had previously set it to abstract_target and this caused the described error. Now it works like a charm
I faced this issue with Xcode 13 betas with the UniformTypeIdentifiers.framework. The app failed to run on iOS versions lower than 13.
The below approach fixed the issue :
Go to the target -> Build Phases -> Link Binary With Libraries -> Add the framework -> Add the status as "Optional"
The above worked perfectly for me! Hope this helps!
For Xcode 8, some stale products will be removed from derived data folder refer to this solution.
Apple: In macOS 10.12 and later, Xcode cleans up stale derived data, precompiled headers, and module caches. (23282174)
The Xcode build system supports stale file removal of some types of build artifacts that were produced in a previous build, but have since been removed from the project.
Base on the author's thought, I found this build log from my case.
Remove stale build products
/bin/rm -rf /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks/AliyunVodPlayerSDK.framework
/bin/rmdir /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks
After creating a new copy file phase and copy the target stale framework to Frameworks destination, the above removal log disappears after rebuilding.
Just clarify my situation and reason, hope it's helpful for someone.
For me this was the solution, after many hours of searching!!
For some reason, well into the development of a Swift 2.3 custom Framework, Xcode 8 had removed the DYLIB_INSTALL_NAME_BASE setting from the project.pbxproj file. A little walk into the Build Settings / Dynamic Library Install Name Base setting back to #rpath fixed it.
(from https://forums.developer.apple.com/thread/4687)
I found that this issue was related only to the code signing and certificates not the code itself. To verify this, create the basic single view app and try to run it without any changes to your device. If you see the same error type this shows your code is fine. Like me you will find that your certificates are invalid. Download all again and fix any expired ones. Then when you get the basic app to not report the error try your app again after exiting Xcode and perhaps restarting your mac for good measure. That finally put this nightmare to an end. Most likely this has nothing to do with your code especially if you get Build Successful message when you try to run it. FYI
Got the issue when trying Xcode 9 beta and going back to Xcode 8. A simple Clean on the target resolved the issue.
I had the same issue for a different reason.
I've created a new configuration to Debug and Release (under PROJECT -> Info tab -> Configuration).
And I had to change my pod frameworks shell script (Pods-"appName"-frameworks.sh , under Targets Support Files) to make it work.
[Xcode 9]
The only thing that worked for me:
Target > Build Phases > [CP] Embed Pods Frameworks
Uncheck "Show environment variables in build log" and "Run script only when installing"
I tried many fixes, but what worked for me was to delete a missing target listed in the build tab of the build scheme. You can get to it by opening the edit window of the current scheme.
Edit: My UI testing target was not working as well, and the solution I found was to delete it and generate it again.
open xcode -> general -> Embedded Binaries -> add QBImagepicker.framework and RSKImageCropper -> clean project
just add QBImagePicker.framework and RSKImageCropper.framework at embedded binaries worked for me
I think there is no fixed way to solve this problem since it might be caused by different reason. I also had this problem last week, I don't know when and exactly what cause this problem, only when I run it on simulator with Xcode or try to install it onto the phone, then it reports such kind of error, But when I run it with react-native run-ios with terminal, there is no problem.
I checked all the ways posted on the internet, like renew certificate, change settings in Xcode (all of ways mentions above), actually all of settings in Xcode were already set as it requested before, none of ways works for me. Until this morning when I delete the pods and reinstall, the error finally gonna after a week. If you are also using cocoapod and then error was just show up without any specific reason, maybe you can try my way.
Check my cocoapods version.
Update it if there is new version available.
Go to your project folder, delete your Podfile.lock , Pods file, project xcworkspace.
Run pod install
I experienced that problem only when running on real device (iPhone SE). On simulator project worked as expected.
I did try all fixes from this very thread and from here.
None of those worked for me.
For me problem was solved after restarting iPhone (sic!).
I did:
clean build folder,
clean derived data,
delete app from device,
reboot device
And it finally works. :)
If every other solution fails don't forget to try it out.
Xcode 11 :
Build Phases -> Embed Frameworks
This might happen with Pod Frameworks.
I was facing the same issue with AnswerBotProvidersSDK.framework and my mistake was, I set Run Script checked for Install builds only in targets build phases.
Incorrect settings:
Correct Settings:
For me for some reason xCode (12.5 up to this moment) decided that my Notification Service Extension Target should not have correct paths to frameworks. I suspect that this is happened after I've updated from xCode 12.1 to 12.5.
So I was getting the same error related to one of my internal frameworks. To fix this problem do the following:
go to Project's General Tab
Select your target (in my case it was Notification Service Extension Target)
Make sure that Framework and Libraries section contains your missing framework. I've left it Embed Without Signing in my NSE Target, but it is also was added with Embed & Sign to my primary app target
Keep your target selected and switch to Build Settings tab
There in a search bar enter LD_RUNPATH_SEARCH_PATHS (make sure that All possible settings will be displayed and not just Basic)
You will see Runpath Search Paths and it was empty for me.
Add 3 following values there:
$(inherited)
#executable_path/Frameworks
#executable_path/../../Frameworks
This is what helped me.

ld: library not found for (on Simulator only)

Suddenly began getting this error when running my app on iOS 7 Simulator.
ld: library not found for -lacmobileshim
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
On Device this problem doesn't happen and the app runs OK.
Have already searched for this library inside SDK but couldn't find it. Have no idea what's going on cause it was running OK both on Simulator and Devices before and haven't added any additional library to my project.
Is there a way to set Library Search Path in Build Settings just for this library?
Should reinstall SDK be a workaround?
These are the libraries i'm including in my project:
After get the same headache as updated to Xcode 6/iOS 8 sdk, just found a simple way to solve this issue with libacmobileshim.dylib and also other dynamic libraries that were causing the same problem when building the app on simulator. Just delete the dynamic libraries from Build Phases settings and the app is running perfectly again on simulator. Hope it may help someone with the same problem.
libacmobileshim.dylib is in the iOS Device SDK, but it is not in the simulator SDK. External developers should have no need for this library, so I'm confused as to why you're linking against it.
Looking at that list of libraries that you're linking against, I suspect a bunch of them aren't even needed by your project. You should audit that list and eliminate unnecessary linkage.

Resources