609

This crash has been a blocking issue I used the following steps to reproduce the issue:

  • Create a Cocoa Touch Framework project
  • Add a swift file and a class Dog
  • Build a framework for device
  • Create a Single View application in Swift
  • Import framework into app project
  • Instantiate swift class from the framework in ViewController
  • Build and run an app on the device

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?

yoAlex5
  • 13,571
  • 5
  • 105
  • 98
vladof81
  • 24,145
  • 9
  • 35
  • 40
  • 2
    What I don't understand is why all other third party frameworks work out of the box and can easily be dragged and dropped into `Link Binary with Libraries` and somehow Xcode knows to copy them into your app bundle, whereas for custom frameworks this simply doesn't happen. – fatuhoku Feb 17 '16 at 12:42
  • sazzad hissain khan's answer here http://stackoverflow.com/questions/26024100/dyld-library-not-loaded-rpath-libswiftcore-dylib is the best answer.. – Ankit Kumar Apr 28 '16 at 05:42
  • 1
    Check out this https://stackoverflow.com/a/52129141/2020034. It works – Vinayak Parmar Sep 01 '18 at 14:40
  • you can make a fat library , you can see this link : https://stackoverflow.com/a/54977145/3992606 – mohsen Mar 04 '19 at 05:30
  • **Xcode version does not match**, solved with https://stackoverflow.com/a/55738882/5443510 . – Jimmy Yin Apr 18 '19 at 03:55

32 Answers32

1007

In the target's General tab, there is an Embedded Binaries field. When you add the framework there the crash is resolved.

Reference is here on Apple Developer Forums.

Cesare
  • 8,326
  • 14
  • 64
  • 116
vladof81
  • 24,145
  • 9
  • 35
  • 40
  • 75
    I have the framework in the Embedded Binaries and I have the Copy Phase as well set to "Frameworks". It crashes anyways. – loretoparisi Sep 18 '14 at 10:22
  • 11
    This only solved on debugging mode. Error will again occur when you archive or build a project – Saad Ur Rehman Dec 09 '14 at 10:24
  • same problem here too bro, seems Xcode is not stable enough – user2727195 Dec 25 '14 at 02:48
  • 14
    Adding @executable_path/Frameworks to the 'Runpath Search Path' solved this problem i.e. in addition to adding the framework to 'Embedded Binaries' – ArdenDev Jan 05 '15 at 19:56
  • On Xcode 6.1.1 adding it to embedded binaries was enough for me. It works both in debug and when archiving builds. – ToddH Feb 05 '15 at 18:17
  • Thank you :) that worked, I had this problem with ReactiveCocoa – Edward Ashak Mar 19 '15 at 17:43
  • 16
    Anyone can help how to add framework in Embedded Binaries, from PODs ? – Bonnke Jul 27 '15 at 18:25
  • 3
    Ditto. I'd also like to know how to add from PODs, given there is no "General > Embedded Binaries" to be found in XCode 6.4 using PODS – ded Jul 31 '15 at 20:02
  • I quote @Bonnke: I'm having the same problem running UI Tests on an app importing RestKit with CocoaPods. Any suggestion about adding frameworks in this case. – Claus Nov 30 '15 at 12:31
  • 3
    I have already added the framework in the Embedded Binaries section but still the app crashes with the message in the console "dyld: library not loaded: reason: image not found" appears if the app is allowed to run on the device with iOS 9.1 where as the app smoothly runs on the simulator. – Md Rais Dec 03 '15 at 09:38
  • Same problem occurred, and solution not working in xcode 7.2 just after revoking the certificate. – Naveed Ahmad Feb 22 '16 at 19:16
  • Works, but this causes `Found an unexpected Mach-O header` error when try to generate ipa. Any idea? – jose920405 May 11 '16 at 19:05
  • How does this work for dynamic *libraries* (not frameworks)? In that case adding it to the *Embadded binaries* is not an option – Gee.E Jun 01 '16 at 08:20
  • You can change the framework to from Required to Optional in your app project. Link Binary With Libraries, but it did not completely resolve the problem, the app crashed when I create an instance of class – Vin Jul 05 '16 at 16:42
  • This really helped me. While the subsequent error shown missing @rpath/libSwift* I had to enable 'Embedded Content Contains Swift Code' as well because my new version of embedded framework is now written in Swift unlike the older version. – igraczech Aug 17 '16 at 12:24
  • 2
    I found over at this SO post (http://stackoverflow.com/questions/26104975/dyld-library-not-loaded-rpath-libswiftcore-dylib-image-not-found) that worked for me. It was by adding to the Runpath Search Paths the string @executable_path/Frameworks. After doing this the error stopped appearing. – Micah Montoya Oct 18 '16 at 14:41
  • I needed all of this information plus the extra bit in my own contributed answer. Maybe Xcode 8 is throwing new wrinkles and bugs at us to keep it fun. – BaseZen Oct 24 '16 at 21:22
  • 1
    That apple link is broken – vish Jul 22 '17 at 04:16
  • 2
    this answer is hugely out of date – Fattie Sep 21 '17 at 17:31
  • in a real device i tested whole ways and did not get answer, but finally I removed cocoaPod from my project and again reinstall it, the problem solved and my app run in device!! this is the remove cocoaPod answer : https://stackoverflow.com/a/34765245/2201814 – MHSFisher Feb 12 '18 at 06:54
  • This solution will work. Don't forget a clean and delete of derived data for good luck (that helped me). Good luck! – Henry Heleine Sep 16 '19 at 16:48
  • 3
    You have to set `Embed & Sign` for your SharedCode framework in "Frameworks, Libraries & Embedded Content – luckyhandler Jan 09 '20 at 09:59
  • 1
    As @luckyhandler wrote, on Xcode 11 and above the lists of "Linked Frameworks and Libraries" and "Embedded Binaries" are combined into a single list named "Frameworks, Libraries & Embedded Content". There, you should find your .framework in the list, and change to "Embed & Sign" – brkeyal Jan 09 '20 at 15:23
  • 1
    For some reason my framework was on the list after I added it to the project but it was set to "Do not embed" by XCode 11. Changed it to Embed & Sign and it worked. – borisgolovnev Feb 28 '20 at 10:44
266

For iOS greater than or equal to 8

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.

enter image description here

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.

For iOS less than 8

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.

Static Framework

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.

Yash R
  • 247
  • 1
  • 18
Dawson
  • 4,291
  • 1
  • 20
  • 33
131

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

  • Develop your framework.
  • Once your development is complete, COMMAND+B build your framework and ensure you receive "Build Succeeded".

enter image description here

2) Access your framework

  • Once your framework project successfully builds it will then be ready for you to access in your Products folder in your project.

enter image description here

  • Right click on your .framework and select "Show in Finder".

enter image description here

3) Place framework in your project

  • Drag and drop the .framework from your Finder window to your app project's "Framework" folder.

enter image description here

4) Configure app project for framework

  • Select the top level in your project

enter image description here

  • Choose your target

enter image description here

  • Go to "Build Phases", then "Link Binary with Libraries", and ensure that your framework is included with optional selected.

enter image description here

  • Still in "Build Phases", go to the upper left and select the + button. In the drop down choose "New Copy Files Phase".

enter image description here

  • Scroll down to the new "Copy Files" section and ensure that you set Destination to "Frameworks". Leave the subpath empty. Then click the + button at the bottom left.

enter image description here

  • You will be presented with your project hierarchy. Scroll down to the "Frameworks" folder that you added the framework to in step 3, or search for it in the search bar at the top. Select your framework and click "Add".

enter image description here

  • Ensure that your framework is included with "Code Sign On Copy" selected.

enter image description here

5) Clean, then run your project

  • COMMAND+SHIFT+K
  • COMMAND+R
Brandon A
  • 7,281
  • 3
  • 34
  • 70
  • 6
    Good point. It almost works for me. I made a framework A, which inclue Alamofire. My host App(embedded framework A) works in simulators. But when I try to run it in a real iPhone, it crashes with error: Alamofire: dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire Reason: no suitable image found. Did find: xxx/ddcdemo.app/Frameworks/iddc.framework/Frameworks/Alamofire.framework/Alamofire: mach-o, but wrong architecture – DàChún Sep 11 '17 at 14:27
  • 1
    @Brandon Making optional to framework solved my issue. But can you please explain me what is the behaviour of making framework optional ? – Mitesh Dobareeya Nov 10 '17 at 07:25
  • 2
    Thank you! In your step 5, I had "Copy only when installing" checked and that was my issue. – Andi Feb 26 '18 at 19:18
  • Your 4th step solved my issue – ViruMax Dec 01 '20 at 09:37
49

Firstly Try to build after Command+Option+Shift+K .If still fails then do below steps.

If anybody is facing this error in Xcode 8 then change your framework status to Optional instead of Required under the General Tab of your target.

enter image description here

Desert Rose
  • 3,238
  • 1
  • 27
  • 35
  • 3
    This will make runtime to not recognize classes from the framework – nsinvocation Sep 15 '16 at 22:29
  • @azimov is correct. I'm facing this dilemma at the moment. Required causes the "image not found" error and if we try setting it to optional it will crash at runtime with "unrecognized selector" – Adam Mendoza Sep 17 '16 at 06:30
  • 1
    Even though my framework was already in Link Binaries and Embed, I still had to add a Copy Phase. dyld: Library not loaded: @rpath/AFNetworking.framework/AFNetworking Referenced from: /Users/{User}/Library/Developer/CoreSimulator/Devices/6833A85C-5783-45FA-A4D5-991D286B28C2/data/Containers/Bundle/Application/B1A0A3B2-92A2-41B0-9884-6DB6995A0D7E/MyApp.app/MyApp Reason: image not found (lldb) Solution: Project -> Target -> Build Phases -> + at top to add new Copy Files phase Destination = Frameworks Select the Framework that needs to be copied – Adam Mendoza Sep 17 '16 at 20:37
  • @AdamMendoza I had my app rejected because of doing that. – jbouaziz Sep 22 '16 at 10:26
  • @jbouaziz, yes, an error you may run into is due to the .framework being fat, meaning it has architectures that are no supported on iOS such as i386 x86_64 besides the necessary armv7 arm64. The store will give you an error, but you may not see the error in Xcode. Use the loader under Xcode -> Open Developer Tool -> Application Loader. SolutionL make it thin see -> http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/ – Adam Mendoza Sep 22 '16 at 10:51
  • @AdamMendoza it was a different error, it was saying that I couldn't copy anything to the Framework folder. That's why it was rejected. – jbouaziz Sep 22 '16 at 13:14
  • @jbouaziz, you picked my interest. Do you mean the app's Frameworks folder? This is allowed. I just submitted an app and included the AFNetworking.framework and was able to submit to the store. Now, inside the AFNetworking.framework package, which is just a folder, you are not allowed to have non-code files such a .txt files. – Adam Mendoza Sep 23 '16 at 03:50
  • @AdamMendoza I managed to fix it by removing the embedded content contains swfit from my custom framework. What happened was that it was creating a framework folder for the swift libraries which wasn't needed. – jbouaziz Sep 23 '16 at 14:34
  • The way I got it to work is clearing the derived data. – avismara Sep 30 '16 at 05:22
  • set Optional will fix my problem – dip Dec 04 '16 at 16:50
  • This was the fix necessary for my scenario: deploying an app to an iPad running 9.3.1. The app contained code that runs on iOS10 only (UNUserNotifications framework). While I put the correct safeguards in the code so it would BUILD for 9.3.1, was getting this error at runtime. – Typewriter Feb 15 '17 at 20:11
49

I created a framework using Swift3/Xcode 8.1 and was consuming it in an Objective-C/Xcode 8.1 project. To fix this issue I had to enable Always Embed Swift Standard Libraries option under Build Options.

Have a look at this screenshot:

enter image description here

Dharman
  • 21,838
  • 18
  • 57
  • 107
NeverHopeless
  • 10,503
  • 4
  • 33
  • 53
  • 3
    This did now work for me at at. The solution to this problem is to go to BuildPhases -> Copy Files -> select Framework under Destination and add your framework. Chances are your libraryis missing here. – Harish Nov 11 '16 at 02:32
  • @Harish, The solution you are suggesting is already suggested by several and definitely i take care of that at first point. In my case the framework was added there but still the same issue appeared. Then i dig it by myself. If you have down voted this solution i don't know why you are pretty sure about your way when it didn't work in my case :S – NeverHopeless Nov 11 '16 at 05:39
  • @Harish Thanks. Your answer helped me much more and ofcourse NeverHopeless's also did :) Thanks you guys – Mohsin Khubaib Ahmed Nov 30 '16 at 13:31
  • This was the only thing that worked for me.. but I'm already "embedding" the framework in my target's `Embedded Binaries` section. So why does this make it work? – abc123 Feb 17 '17 at 17:19
  • Awesome this thing works because if using a swift library or a pod to embed in objective C project. Objective C project often has this flag to No. – Swaroop S Feb 27 '18 at 09:50
28

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.

jfalexvijay
  • 3,678
  • 7
  • 37
  • 67
  • This works. Does anybody know why? Cuz some devices need this setting others do not. – NEO Aug 10 '17 at 03:37
  • I get "warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available." when mark my lib as an optional – BergP Feb 22 '18 at 12:30
  • it's worked maybe the reason is some framework didn't run in simulator that's why – Gowtham Sooryaraj Jul 17 '18 at 11:32
  • @redent84 This answer, along with your comment, saved me from getting insane. Ran into this issue with AuthenticationServices.framework, which requires iOS 12. – Tamás Sengel Sep 20 '18 at 07:14
27

I had to (on top of what mentioned here) add the following line to Runpath Search Paths under Build Settings tab:
@executable_path/Frameworks

enter image description here

Aviel Gross
  • 8,880
  • 2
  • 47
  • 58
  • This fixed the issue for me. I started having the problem after adding an app extension to my iOS 9 app. Before adding the extension, my framework was found just fine. Adding a Copy Files build phase did not help, and I was already embedding the framework. – Greg Dec 12 '16 at 16:25
  • It is so strange this is not included by default. If you unzip and look at your IPA, you should find your frameworks in Payloads/appname.app/Frameworks/. However, adding this search path has to be there for the app to look in this folder during runtime. Weird. – mattv123 Jan 21 '17 at 00:41
26

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

Community
  • 1
  • 1
liamnichols
  • 12,109
  • 2
  • 40
  • 62
  • After trying so many things, this is what solved it for me. I already had the framework in Link Binary and Embed Framework. I didn't think I had to also add a Copy Phase but this fixed it. – Adam Mendoza Sep 17 '16 at 21:49
16

If you're using Xcode 11 or newer:

  1. Navigate to the settings of your target and select General.

Target Settings/General

  1. Scroll down to Frameworks, Libraries and Embedded Content.

  2. Make sure the Embed & Sign or Embed Without Signing value is selected for the Embed option if necessary.

Frameworks, Libraries and Embedded Content section

Tamás Sengel
  • 47,657
  • 24
  • 144
  • 178
14

It is a runtime error that is caused by Dynamic Linker

dyld: Library not loaded: @rpath/<some_path>
Referenced from: <some_path>
Reason: image not found

The error Library not loaded with @rpath indicates that Dynamic Linker cannot find the binary.

  1. Check if the dynamic framework was added to General -> Frameworks, Libraries, and Embedded Content (Embedded Binaries). It is very simple to drag-and-drop a framework to project with Copy items if needed[About] and miss to add the framework as implicit dependency in
    Frameworks, Libraries, and Embedded Content(or check in Add to targets). In this case during compile time Xcode build it as success but when you run it you get runtime error

  2. Check the @rpath setup between consumer(application) and producer(dynamic framework):

  • Dynamic framework:
    • Build Settings -> Dynamic Library Install Name
  • Application:
    • Build Settings -> Runpath Search Paths
    • Build Phases -> Embed Frameworks -> Destination, Subpath
  1. Framework's Mach-O file[About] - Dynamic Library and Application's Frameworks, Libraries, and Embedded Content[About] - Do Not Embed.

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

Relative path allows you to define a path in a dynamic way.

@executable_path

@executable_path - relative to executable binary which loads framework
use case: Dynamic framework inside Application(application binary path is @executable_path) or more complex example with App Extension[About] which is a part of Containing App with Dynamic Framework inside. There 2 @executable_path for Application target (application binary path is @executable_path) and for App Extension target(App Extension binary path is @executable_path)) - Framework2 example

//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 causes framework to be loaded. If it is an application than it will be the same as @executable_path
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

@rpath - Runpath Search Path

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. Since this setup is made on Framework target side it is not possible to configure the same framework for different consumers(applications)

@rpath is a compound concept that relies on outer(Application) and nested(Dynamic framework) parts:

  • Application:

    • Runpath Search Paths(LD_RUNPATH_SEARCH_PATHS) - @rpath - defines a list of templates which will be substituted with @rpath. Consumer uses @rpath word to point on this list

       @executable_path/../Frameworks
      
    • Review Build Phases -> Embed Frameworks -> Destination, Subpath to be sure where exactly the embed framework is located

  • Dynamic Framework:

    • Dynamic Library Install Name(LD_DYLIB_INSTALL_NAME) - points 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

[Vocabulary]

[Java ClassLoader]

yoAlex5
  • 13,571
  • 5
  • 105
  • 98
13

Add the framework in Embedded Binaries enter image description here

Then Clean and Build.

Vineesh TP
  • 7,025
  • 9
  • 54
  • 102
11

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.

BaseZen
  • 8,306
  • 2
  • 31
  • 45
  • 1
    Thank you, this turned out to be my issue in Xcode 11. I was importing one of my own frameworks, which previously worked, but started issuing the "dyld: Library not loaded" error. To be clear, you want to set the build setting "Dynamic Library Install Name Base" to "@rpath" in the project of the framework you're trying to import, *not* in the project you are importing into. Somehow it got set to "/Library/Frameworks". – Ben Stahl Dec 04 '19 at 00:08
  • Glad this was helpful 3 years later. Edited accordingly. – BaseZen Dec 05 '19 at 14:09
10

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

  1. In your Projects, select the target.
  2. Goto General tab on top.
  3. Under the 'Frameworks, Libraries and Embedded Content' section, add the framework (for me it was CoreNFC). Repeat for other targets.
  4. Click on Build Phases on top and expand 'Link Binary with Libraries'.
  5. Make the troublesome framework optional (from required).

This allowed me to compile for older/newer iPhones without making any code changes. I hope this helps other.

whawhat
  • 165
  • 2
  • 7
9

My environment: Cocos2d 2.0, Box2d, Objective C

In addition to doing the other answers above I finally went to the General tab and made WatchKit Optional.

Target General Linked Frameworks and Libraries Watchkit.framework Optional

Jim Rota
  • 1,743
  • 2
  • 16
  • 20
9

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.

Nef10
  • 894
  • 2
  • 16
  • 25
Andrea Leganza
  • 402
  • 7
  • 7
8

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!

NYC Tech Engineer
  • 1,677
  • 2
  • 20
  • 23
8

enter image description here

Resolved for me by unselecting "Copy only when installed" on Build Phases->Embed Frameworks

Shohin
  • 225
  • 3
  • 4
  • 1
    It would be nice to know the point of this checkbox if the system does not believe that "debug install" is not "install". Regardless, if it causes a crash of the app on the hardware instead of prohibiting the run of the app with a warning, it's a neat another Xcode defect – Cerniuk Nov 25 '18 at 05:22
5

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.

henrik-dmg
  • 1,211
  • 13
  • 20
5

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
Stéphane de Luca
  • 10,239
  • 7
  • 45
  • 74
4

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.

User18474728
  • 273
  • 1
  • 11
3

The simple solution is follow this screenshot then crash will go away:

enter image description here

Noted: This is Xcode 11.5

Sour LeangChhean
  • 4,895
  • 4
  • 29
  • 35
2

If have development pod Delete your app from simulator install from pod -> clean - > run again...

Rajesh Kumar
  • 782
  • 9
  • 18
2

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.

atereshkov
  • 2,967
  • 1
  • 25
  • 36
1

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.

Vittal Pai
  • 2,725
  • 18
  • 28
1

Xcode 11

  1. Navigate to settings of your target and select General.
  2. Look for "Frameworks, Libraries, and Embedded Content"
  3. Keep "Do Not Embed" and make sure that all your targets (if you have more than one) have only set it's own framework and not others targets.
Matias Jurfest
  • 1,174
  • 12
  • 23
1

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.

enter image description here

2: Second change the name of the added phase to Embed Frameworks enter image description here

3: Change the destination to Frameworks.

enter image description here

4: Add the framework for which the error occurred.

enter image description here

vinay
  • 311
  • 1
  • 4
  • 14
1

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):

  1. Go to the "Project Navigator" (i.e. the first icon to show all project items etc)

  2. Select your project from the top of the tree.

  3. On the menu in the middle of the page (slightly to the right), select your application under "Targets"

  4. From the top-tab, select "General"

  5. Scroll down to "Frameworks, Libraries and Embedded Content"

  6. Select your Lib from the list

  7. Select "Embed & Sign" from the drop down list next to it.

  8. Clean

  9. Re-Build and run.

I hope this helps.

H

Heider Sati
  • 1,928
  • 20
  • 23
0
  1. Go to file in xcode -> Workspace settings
  2. Click the arrow next to which appears /Users/apple/Library/Developer/Xcode/DerivedData
  3. Select the Derived data and move it to Trash.
  4. Quite the xcode and reopen it.
  5. Clean the project and run again.

Above steps resolved my issuses.

john raja
  • 311
  • 2
  • 5
0

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. – enter image description here

0

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.

Bozzo
  • 289
  • 1
  • 3
  • 13
0

For me, I had to switch the XcodeKit.framework from "Do Not Embed" -> "Embed & Sign"

enter image description here

-4

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

Sam
  • 5,822
  • 1
  • 22
  • 27
  • Exactly. Code signing has nothing to to with this error. – igraczech Aug 17 '16 at 12:24
  • In this particular case where the signing certificate is not trusted or not in the keychain, the Signature is invalid is the actual error followed by library not found. So I will support this answer. Yet it do not fit to the logs in question but it will help somebody. cheers! – SaadurRehman Nov 17 '20 at 14:02