Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app with framework crashed on device, dyld: Library not loaded, Xcode 6 Beta

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?

like image 854
vladof81 Avatar asked Jun 20 '14 19:06

vladof81


5 Answers

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.

like image 168
vladof81 Avatar answered Oct 23 '22 18:10

vladof81


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.

like image 34
Dawson Avatar answered Oct 23 '22 20:10

Dawson


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
like image 138
Brandon A Avatar answered Oct 23 '22 18:10

Brandon A


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

like image 52
Desert Rose Avatar answered Oct 23 '22 18:10

Desert Rose


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

like image 50
NeverHopeless Avatar answered Oct 23 '22 19:10

NeverHopeless