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

我只是一个虾纸丫 提交于 2019-11-26 00:17:16

问题


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?


回答1:


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.




回答2:


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.

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.

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.




回答3:


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".

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.

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

3) Place framework in your project

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

4) Configure app project for framework

  • Select the top level in your project

  • Choose your target

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

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

  • 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.

  • 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".

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

5) Clean, then run your project

  • COMMAND+SHIFT+K
  • COMMAND+R



回答4:


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.




回答5:


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:




回答6:


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.




回答7:


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




回答8:


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




回答9:


Add the framework in Embedded Binaries

Then Clean and Build.




回答10:


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.




回答11:


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!




回答12:


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 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, it was instructing the host App to dynamically load it at runtime from /Library/Frameworks/fw.Framework/fw (as in, the root of the 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.




回答13:


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.




回答14:


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




回答15:


If you're using Xcode 11 or newer:

  1. Navigate to the settings of your target and select 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.




回答16:


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.




回答17:


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.




回答18:


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




回答19:


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.




回答20:


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. –




回答21:


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.




回答22:


  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.




回答23:


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.



回答24:


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.




回答25:


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



来源:https://stackoverflow.com/questions/24333981/ios-app-with-framework-crashed-on-device-dyld-library-not-loaded-xcode-6-beta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!