This crash has been a blocking issue I used the following steps to reproduce the issue:
The app immediate crashed upon launching, here is console log:
dyld: Library not loaded: @rpath/FrameworkTest03.framework/FrameworkTest03
Referenced from: /var/mobile/Applications/FA6BAAC8-1AAD-49B4-8326-F30F66458CB6/FrameworkTest03App.app/FrameworkTest03App
Reason: image not found
I have tried to build on iOS 7.1 and 8.0 devices, they both have the same crash. However, I can build an app and run on the simulator fine. Also, I am aware that I can change the framework to form Required to Optional in Link Binary With Libraries, but it did not completely resolve the problem, the app crashed when I create an instance of Dog. The behavior is different on the device and simulator, I suspect that we can't distribute a framework for the device using a beta version of Xcode. Can anyone shed light on this?
I had the same issue. I tried building my project with an iPhone that I never used before and I didn't add a new framework. For me, cleaning up worked fine (Shift+Command+K). Maybe it's because I use beta 5 of Xcode 7 and an iPhone 6 with iOS 9 Beta, but it worked.
Try with changing flag ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES
(in earlier xcode versions: Embedded Content Contains Swift Code
) in the Build Settings from NO to YES.
It is a runtime error that is caused by Dynamic Linker
dyld: Library not loaded: @rpath/...
...
Reason: image not found
The error Library not loaded
with @rpath
indicates that Dynamic Linker
cannot find the binary.
Check if the dynamic framework was added to General -> Embedded Binaries
Check the @rpath
setup between consumer(application) and producer(dynamic framework):
Build Settings -> Dynamic Library Install Name
Build Settings -> Runpath Search Paths
Build Phases -> Embed Frameworks -> Destination, Subpath
Dynamic linker
Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME)
which is used by loadable bundle
(Dynamic framework
as a derivative) where dyld
come into play
Dynamic Library Install Name
- path to binary file(not .framework). Yes, they have the same name, but MyFramework.framework
is a packaged bundle
with MyFramework
binary file and resources inside.
This path to directory can be absolute or relative(e.g. @executable_path
, @loader_path
, @rpath
). Relative path is more preferable because it is changed together with an anchor that is useful when you distribute your bundle as a single directory
absolute path - Framework1 example
//Framework1 Dynamic Library Install Name
/some_path/Framework1.framework/subfolder1
@executable_path
@executable_path - relative to entry binary - Framework2 example
use case: embed a Dynamic framework
into an application
//Application bundle(`.app` package) absolute path
/some_path/Application.?pp
//Application binary absolute path
/some_path/Application.?pp/subfolder1
//Framework2 binary absolute path
/some_path/Application.?pp/Frameworks/Framework2.framework/subfolder1
//Framework2 @executable_path == Application binary absolute path
/some_path/Application.?pp/subfolder1
//Framework2 Dynamic Library Install Name
@executable_path/../Frameworks/Framework2.framework/subfolder1
//Framework2 binary resolved absolute path by dyld
/some_path/Application.?pp/subfolder1/../Frameworks/Framework2.framework/subfolder1
/some_path/Application.?pp/Frameworks/Framework2.framework/subfolder1
@loader_path
@loader_path - relative to bundle which is an owner of this binary
use case: framework with embedded framework - Framework3_1 with Framework3_2 inside
//Framework3_1 binary absolute path
/some_path/Application.?pp/Frameworks/Framework3_1.framework/subfolder1
//Framework3_2 binary absolute path
/some_path/Application.?pp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
//Framework3_1 @executable_path == Application binary absolute path
/some_path/Application.?pp/subfolder1
//Framework3_1 @loader_path == Framework3_1 @executable_path
/some_path/Application.?pp/subfolder1
//Framework3_2 @executable_path == Application binary absolute path
/some_path/Application.?pp/subfolder1
//Framework3_2 @loader_path == Framework3_1 binary absolute path
/some_path/Application.?pp/Frameworks/Framework3_1.framework/subfolder1
//Framework3_2 Dynamic Library Install Name
@loader_path/../Frameworks/Framework3_2.framework/subfolder1
//Framework3_2 binary resolved absolute path by dyld
/some_path/Application.?pp/Frameworks/Framework3_1.framework/subfolder1/../Frameworks/Framework3_2.framework/subfolder1
/some_path/Application.?pp/Frameworks/Framework3_1.framework/Frameworks/Framework3_2.framework/subfolder1
Framework2 example
Previously we had to setup a Framework to work with dyld. It is not convenient because the same Framework can not be used with a different configurations
@rpath
is a compound concept that relies on outer(Application) and nested(Dynamic framework) parts:
Application:
Runpath Search Paths(LD_RUNPATH_SEARCH_PATHS)
- defines a list of templates which be substituted with @rpath
.
@executable_path/../Frameworks
Build Phases -> Embed Frameworks -> Destination, Subpath
to be shire where exactly the embed framework is locatedDynamic Framework:
Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME)
- point that @rpath
is used together with local bundle path to a binary
@rpath/Framework2.framework/subfolder1
//Application Runpath Search Paths
@executable_path/../Frameworks
//Framework2 Dynamic Library Install Name
@rpath/Framework2.framework/subfolder1
//Framework2 binary resolved absolute path by dyld
//Framework2 @rpath is replaced by each element of Application Runpath Search Paths
@executable_path/../Frameworks/Framework2.framework/subfolder1
/some_path/Application.?pp/Frameworks/Framework2.framework/subfolder1
*../
- go to the parent of the current directory
otool
- object file displaying tool
//-L print shared libraries used
//Application otool -L
@rpath/Framework2.framework/subfolder1/Framework2
//Framework2 otool -L
@rpath/Framework2.framework/subfolder1/Framework2
//-l print the load commands
//Application otool -l
LC_LOAD_DYLIB
@rpath/Framework2.framework/subfolder1/Framework2
LC_RPATH
@executable_path/../Frameworks
//Framework2 otool -l
LC_ID_DYLIB
@rpath/Framework2.framework/subfolder1/Framework2
install_name_tool
change dynamic shared library install names using -rpath
CocoaPods
uses use_frameworks!
[About] to regulate a Dynamic Linker
In my case app crash only on real device and it occurred for standard library's. I tryied a lot of steps meintioned before, after 1h i just delete app from real device and install it again.
The same thing was when I've created a new Configuration and Build Scheme.
So the solution for me was to run
pod install
for this newly created Configuration.
If you are using a third-party framework, and using Cocoapods as your dependency manager, try doing a pod install
to refresh your pods.
This crash was occurring on a third-party library I was using, so glad the above solution worked for me, hope it works for you!
In my case the solution was to remove the compiled framework from the Embedded Binaries, which was a standalone project in the workspace, clean and rebuild it, and finally re-add to Embedded Binaries.
Xcode 11
Recently ran into this issue with importing CoreNFC on older iphones (e.g. iPhone 6) and Xcode (11.3.1). I was able to get it to work by
This allowed me to compile for older/newer iPhones without making any code changes. I hope this helps other.
I got same kind of issue in iOS 9.x version
ISSUE IS: App crashes as soon as I open the app with below error.
dyld: Library not loaded: /System/Library/Frameworks/UserNotifications.framework/UserNotifications Referenced from: /var/containers/Bundle/Application/######/TestApp.app/TestApp Reason: image not found
I have resolved this issue by changing Required
to Optional
in Linked Frameworks and Libraries
for UserNotifications.framework
framework.
In Xcode 11
I was facing the same issue
Changing "Do Not Embed" in General Tab > "Frameworks, Libraries, and Embedded Content" was still resulting the same error.
What did solved for me was adding the Framework in Build Phases Tab > Embed Frameworks section
--Updated---
I observed that in projects built in previous versions of Xcode Embed Frameworks Section is not available when running in Xcode 11, Find the below steps to achieve the solution:
1: First need to add the New Copy Files Phase under Build Phases tab.
2: Second change the name of the added phase to Embed Frameworks
3: Change the destination to Frameworks.
4: Add the framework for which the error occurred.
After trying all the methods available on internet and my own trial and error tricks 100 times. Finally I was able to solve it. – Apeksha Sahu 6 mins ago
Goto iTunes in Mac --> accounts-->Authorize this computer – Apeksha Sahu 5 mins ago
second step.... Goto developer in settings in iPad and iPhone and reindex with identifiers and clear trust computers everything. It worked for me........ ....... After reinstalling Mac OSHigh seria 10.13.15 version from Mac OS seirra beta latest version, to reinstalling Xcode latest version, after updating all certificates. etc etc etc... as many methods as you can think I did. –
You need to add the framework to a new Copy Files Build Phase to ensure that the framework is copied into the application bundle at runtime..
See How to add a 'Copy Files build phase' to my Target for more information.
Official Apple Docs: https://developer.apple.com/library/mac/recipes/xcode_help-project_editor/Articles/CreatingaCopyFilesBuildPhase.html
For SumUp Users, if you are loading the latest SumUpSDK.xcFramework, then you need to make sure that it's set to "Embed & Sign" from the application's General tab of the Target.
i.e. to reverse the above statement (making it easier to understand):
Go to the "Project Navigator" (i.e. the first icon to show all project items etc)
Select your project from the top of the tree.
On the menu in the middle of the page (slightly to the right), select your application under "Targets"
From the top-tab, select "General"
Scroll down to "Frameworks, Libraries and Embedded Content"
Select your Lib from the list
Select "Embed & Sign" from the drop down list next to it.
Clean
Re-Build and run.
I hope this helps.
H
Above steps resolved my issuses.
I had to (on top of what mentioned here) add the following line to Runpath Search Paths under Build Settings tab:
@executable_path/Frameworks
Just dragging the framework into your project isn't going to be good enough. That is like being in the same ballpark but not being able to find your kids. Follow these steps:
1) Create your framework
COMMAND
+B
build your framework and ensure you receive "Build Succeeded".2) Access your framework
Products
folder in your project..framework
and select "Show in Finder".3) Place framework in your project
.framework
from your Finder window to your app project's "Framework" folder.4) Configure app project for framework
+
button. In the drop down choose "New Copy Files Phase".Destination
to "Frameworks". Leave the subpath empty. Then click the +
button at the bottom left. 5) Clean, then run your project
COMMAND
+SHIFT
+K
COMMAND
+R
If have development pod Delete your app from simulator install from pod -> clean - > run again...
For any project or Framework project in Xcode that use pods, one easy way to avoid dynamic library (dylb) not to load is to set you pod file to ink in static mode. To do so, just make sure to don't write the following line in your pod file.
use_frameworks!
Once the line deleted from your file which you saved, simply run form the console:
$ pod update
Surprisingly, not all of the necessary pieces are documented here, at least for Xcode 8.
My case was a custom-built framework as part of the same workspace. It turns out it was being built incorrectly. Based on jeremyhu's last response to this thread:
https://forums.developer.apple.com/thread/4687
I had to set Dynamic Library Install Name Base
(DYLIB_INSTALL_NAME_BASE
) under Build Settings
of the Framework Project and then rebuild it. It was incorrectly set to $(LOCAL_LIBRARY_DIR)
and I had to change it to @rpath
.
So in the link processing stage in the App Project, it was instructing the host App to dynamically load the framework at runtime from /Library/Frameworks/fw.Framework/fw
(as in, the root of the runtime filesystem) rather than path-to-App/Frameworks/fw.Framework/fw
Regarding all the other settings: it does have to be in 3 places in Build Phases
, but these are all set at once when you just add it to the Embedded Binaries
setting of the General
tab of the hosting App.
I did not have to set up an extra Copy Files
phase, which seems intuitively redundant with respect to the embedding stage anyway. By checking the tail end of the build transcript we can assure that that's not necessary.
PBXCp /Users/xyz/Library/Developer/Xcode/DerivedData/MyApp-cbcnqafhywqkjufwsvbzckecmjjs/Build/Products/Debug-iphoneos/MyFramework.framework
[Many verbose lines removed, but it's clear from the simplified transcript in the Xcode UI.]
I still have no idea why Xcode set the DYLIB_INSTALL_NAME_BASE
value incorrectly on me.
Under the target's General tab, in the Embedded Binaries section add the framework. This will copy the framework into the compiled so that it can be linked to at runtime.
Why is this happening? : because the framework you are linking to is compiled as a dynamically linked framework and thus is linked to at runtime.
** Note:** Embedding custom frameworks is only supported in iOS > 8 and thus an alternative solution that works on older versions of iOS follows.
If you influence this framework (have access to the source code/build process) you may change this framework to be statically linked rather than dynamically linked. This will cause the code to be included in your compiled app rather than linked to at runtime and thus the framework will not have to be embedded.
** How:** Under the framework's Build Setting tab, in the Linking section, change the Mach-O Type to Static Library. You should now not need to include the framework under embedded binaries.
Including Assets: To include things such as images, audio, or xib/nib files I recommend creating a bundle (essentially a directory, more info here bit.ly/ios_bundle) and then load the assets from the bundle using NSBundle.
In case anyone is still experiencing this issue, despite following all the steps outlined in the many other answers, you may need to revoke and recreate your code signing certificate, as per the following:
https://developer.apple.com/library/ios/qa/qa1886/_index.html
In my case, my project is written by objective-c and in the library there are Swift files. So I changed "Always Embed Swift Standard Libraries" in my project’s Build Settings tab to Yes and it became totally okay.
Source: Stackoverflow.com