96

I'm creating an iOS framework with Xcode6 and iOS8. When I link this with an iOS app and try running it on the device I get this error

dyld: Library not loaded: @rpath/FrameworkName.framework/FrameworkName
  Referenced from: /private/var/mobile/Containers/Bundle/Application/0F2C2461-A68B-4ABA-A604-B88E6E9D1BB1/AppName.app/AppName
  Reason: image not found

The 'Runpath Search Paths' build setting for the framework is set by default to

'@executable_path/Frameworks', '@loader_path/Frameworks'

I could not find any documentation related to this. This was something new introduced with Xcode6 and I would expect it to just work by simply including the framework into any app that needs it.

ArdenDev
  • 4,051
  • 5
  • 29
  • 50
  • You should be creating the framework as a target _in the project_ to start with. _Then_ it will "just work". – matt Jan 30 '15 at 21:00
  • 1
    @Matt, for our use we need to keep it as another project within the same workspace. Any tips on what to do in this scenario ? – ArdenDev Jan 30 '15 at 21:53
  • What *I* would do is this: make a new project and in that project make a new framework target. That builds and runs, so now I know what all the settings need to be for both the app target and the framework target. Now compare. :) – matt Jan 30 '15 at 22:46
  • **Please check this answer. ** https://stackoverflow.com/a/67886532/13439617 – Muhammad Tameem Rafay Jun 08 '21 at 12:04

13 Answers13

80

To make this work

  1. In the framework project settings change the install directory from '/Library/Frameworks' to '@executable_path/../Frameworks'

  2. In the project that includes this framework, add a copy files phase and copy this framework to the 'Frameworks' folder. Once you do this ensure that this framework is listed under the 'Embedded Binaries' section.

ArdenDev
  • 4,051
  • 5
  • 29
  • 50
  • 3
    Thank you for reporting back. I believe this will be of value to others...! – matt Feb 09 '15 at 01:53
  • 5
    Thnx, step 2 was enough for me. – M.Othman Apr 07 '16 at 13:21
  • I had not looked under General -> Embedded Binaries. Adding it there fixed my issue too. – Adam Mendoza Aug 30 '16 at 23:54
  • Also check "Build Settings"->"Linking"->“Dynamic Library Install Name Base” is set to @rpath. – Gavin Jul 27 '17 at 09:26
  • @AdamMendoza I've done same as you mentioned in my framework but i think my problem is different, so can you answer this post if you've idea: https://stackoverflow.com/questions/50384137/library-not-loaded-issue-in-xcode#50384137 – Aleem May 17 '18 at 07:21
  • For anyone hacking around with Cordova plugins for 3rd party frameworks, step two also works if you add src/ios/Frameworks to your cordova plugin and drop your X.framework folder there. Thanks! –  Apr 22 '20 at 21:21
  • In case of framework as sub-xcodeproj: **We needed to change `Dynamic Library Install Name` to `$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)`** but I had `Skip Install` set to `YES` (so, no need for Step 1), and it was already embedded in the App anyway (so, no need for Step 2 either). – Top-Master May 18 '21 at 12:09
45

Issue resolved using this answer. According to @vladof81:

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.

Community
  • 1
  • 1
Tom Howard
  • 4,672
  • 2
  • 43
  • 48
36

I also had same kind of problem where I was not able to launch the app & app was crashing with above message :

dyld: Library not loaded: @rpath/FrameworkName.framework/FrameworkName Referenced from: /private/var/mobile/Containers/Bundle/Application/xxxxxxxxxxxxxxxxxxx

Reason: image not found

Here is my approach that helped me to resolve this error:

  1. From General Tab

Frameworks, Libraries, and Embedded Content

  • add the framework and make sure to make it Embed & Sign

General Tab

  1. From Build Phases

Dependences

  • add the framework to it

Build Phases

Eslam Hanafy
  • 587
  • 7
  • 12
  • 4
    I cannot add framework in Build Phased -> dependences. – Jaydeep Vyas Jan 20 '20 at 13:47
  • 7
    Embed & Sign did the trick. I'm not sure if the second step is necessary but thank you for the answer, upvoted! – Lukas May 12 '20 at 07:18
  • You really deserve a beer brother!! Rock the Party!! Embed & Sign did the trick, I'm not sure if the second step is necessary or not. – Ravi Aug 28 '21 at 04:34
11

Check if you can find framework in context under :

Build Phases > Embed Frameworks >

If not just add that framework in "Embed Frameworks" after adding that framework in your project directory's "Frameworks" section.
enter image description here

Venu Gopal Tewari
  • 5,672
  • 42
  • 41
  • 1
    However, this is not a good solution if you have Fat frameworks because embedding the x86 slice will cause your upload to the app store to fail. See https://stackoverflow.com/questions/30547283/submit-to-app-store-issues-unsupported-architecture-x86?rq=1 – Buddhisthead Sep 10 '19 at 18:34
9

I was getting this error on a library installed through CocoaPods. Cleaning the build folder (cmd + option + shift + k) and then doing a clean (cmd + shift + k) was what ended up resolving this issue for me.

Stunner
  • 12,025
  • 12
  • 86
  • 145
6

If you are using Carthage

Run carthage update on terminal

Go to Project Settings -> Build Phases -> Carthage Copy Frameworks

Add line in Inputs files: $(SRCROOT)/Carthage/Build/iOS/YOURLIBRARY.framework

Add this line to Output files: $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/YOURLIBRARY.framework

pedroremedios
  • 763
  • 1
  • 11
  • 39
Ronaldo Albertini
  • 1,329
  • 20
  • 24
4

Made the library which shows not loaded changed from required to optional in Linked binaries and frameworks. It is working perfectly now

Saranjith
  • 11,242
  • 5
  • 69
  • 122
3

For me it was because of the SSL issue, I had set my developer, distribution certificates on my Mac(Keychain) to 'Always Trust' for one of my other project. I had to change them back to 'Use System Defaults'. it was working for me then!!

Gee Kay
  • 31
  • 4
2

I also had same kind of problem where I was not able to launch the app & app was crashing with above message :

dyld: Library not loaded: @rpath/FrameworkName.framework/FrameworkName Referenced from: /private/var/mobile/Containers/Bundle/Application/xxxxxxxxxxxxxxxxxxx

Reason: image not found

Here is my approach that helped me to resolve this error:

1.Please delete your app from device, Clean the build and and rebuild and run on the device.

2.If above steps does not help you, then please check for below settings :
From "TARGET">"Build Settings">"Runpath Search Paths" & then check for values "$(inherited)" & "@executable_path/Frameworks", Feel free to add incase they don't exist.

Build your app and run it on device

Ash
  • 5,525
  • 1
  • 40
  • 34
1

In addition to the above solutions, recheck the paths of frameworks included in your application under

Build Settings --> Search Paths --> Framework Search Paths

prodeveloper
  • 943
  • 14
  • 22
1

When non of those solution works:

  1. (Optional) Get a clear knowledge from here on different search path type
  2. Make sure that your .framework file paths are added in Build Settings -> Framework Search Paths. You can keep all framework files somewhere in App/libs/ and add this folder and enable recursively.
  3. Make sure that your .a files paths are added in Build Settings -> Library Search Paths.

enter image description here

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

I installed third party libraries using Cocoapods. Got the same error, tried everything but finally realised I havent had use_frameworks! in my pod file.

So removed the currently installed library, added use_frameworks! line in pod file, reinstalled the libraries and all worked for me.

akshayk80
  • 166
  • 2
  • 6
0

The way tested by me is well.

In "Linked Binary With Libraries" change the missing framework to "Embedded Framework".

Because, "Do not Embedded" do not copy to the App, but Embedded Framework will copy into it.

Beckon
  • 128
  • 2
  • 15