带有框架的 iOS 应用程序在设备上崩溃,dyld: 库未加载,Xcode 6 Beta

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

  • Create a Cocoa Touch Framework project
  • Add a swift file and a class Dog
  • Build 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 app on 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 app and run on simulator fine. Also I am aware that I can change the framework to from 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 device and simulator, I suspect that we can't distribute framework for device using beta version of Xcode. Can anyone shed light on this?

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

csdnceshi67
bug^君 Check out this stackoverflow.com/a/52129141/2020034. It works
大约 2 年之前 回复
csdnceshi61
derek5. .. the answer by Dawson below specifically answers your question.
大约 3 年之前 回复
csdnceshi61
derek5. for 2017 Brandon's answer below is correct, the rast are unfortunately out of date
大约 3 年之前 回复
weixin_41568174
from.. sazzad hissain khan's answer here stackoverflow.com/questions/26024100/… is the best answer..
4 年多之前 回复
weixin_41568196
撒拉嘿哟木头 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.
4 年多之前 回复

20个回答

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.

weixin_41568174
from.. Thank you for your help!
大约 2 年之前 回复
weixin_41568134
MAO-EYE Great!!! solution. Nailed it!!
2 年多之前 回复
csdnceshi61
derek5. 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 : stackoverflow.com/a/34765245/2201814
2 年多之前 回复
csdnceshi76
斗士狗 That solved the problem for me thanks!
接近 3 年之前 回复
csdnceshi74
7*4 this answer is hugely out of date
大约 3 年之前 回复
csdnceshi63
elliott.david That apple link is broken
3 年多之前 回复
csdnceshi59
ℙℕℤℝ 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.
大约 4 年之前 回复
weixin_41568127
?yb? I found over at this SO post (stackoverflow.com/questions/26104975/…) 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.
大约 4 年之前 回复
csdnceshi78
程序go 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.
大约 4 年之前 回复
csdnceshi50
三生石@ 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
4 年多之前 回复
weixin_41568110
七度&光 How does this work for dynamic libraries (not frameworks)? In that case adding it to the Embadded binaries is not an option
4 年多之前 回复
csdnceshi68
local-host Works, but this causes Found an unexpected Mach-O header error when try to generate ipa. Any idea?
4 年多之前 回复
weixin_41568184
叼花硬汉 Nope, causes code-signing issues for some reason.
4 年多之前 回复
csdnceshi55
~Onlooker Same problem occurred, and solution not working in xcode 7.2 just after revoking the certificate.
4 年多之前 回复
csdnceshi52
妄徒之命 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.
接近 5 年之前 回复
csdnceshi62
csdnceshi62 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.
接近 5 年之前 回复
csdnceshi64
游.程 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
大约 5 年之前 回复
csdnceshi75
衫裤跑路 Anyone can help how to add framework in Embedded Binaries, from PODs ?
大约 5 年之前 回复
weixin_41568131
10.24 Thank you :) that worked, I had this problem with ReactiveCocoa
5 年多之前 回复
csdnceshi71
Memor.の On Xcode 6.1.1 adding it to embedded binaries was enough for me. It works both in debug and when archiving builds.
5 年多之前 回复
csdnceshi57
perhaps? Adding @executable_path/Frameworks to the 'Runpath Search Path' solved this problem i.e. in addition to adding the framework to 'Embedded Binaries'
接近 6 年之前 回复
csdnceshi67
bug^君 same problem here too bro, seems Xcode is not stable enough
接近 6 年之前 回复
weixin_41568208
北城已荒凉 yes same issue persist when i create ipa file.
接近 6 年之前 回复
csdnceshi54
hurriedly% This only solved on debugging mode. Error will again occur when you archive or build a project
接近 6 年之前 回复
csdnceshi70
笑故挽风 I have the framework in the Embedded Binaries and I have the Copy Phase as well set to "Frameworks". It crashes anyways.
大约 6 年之前 回复

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 and alternative solution that works on older versions of iOS follows.

For iOS less than 8

If you have influence on 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 include 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.

weixin_41568134
MAO-EYE error Swift is not supported for static libraries
4 年多之前 回复
csdnceshi61
derek5. This should be "Greater than or Equal To 8". I've had to do this on iOS 8 as well.
大约 5 年之前 回复
csdnceshi66
必承其重 | 欲带皇冠 What do you mean by "framework is in Pods"? That your custom framework is distributed via CocoaPods?
大约 5 年之前 回复
weixin_41568110
七度&光 How can i add framework to embedded binaries, if framework is in Pods?
大约 5 年之前 回复

I received this same error while attempting to manually add my created framework into my project. 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. It took me some trial and error to get it to work properly but following these steps did it for me.

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
csdnceshi74
7*4 Ohh myyy... it solved the problem. Thanks!
2 年多之前 回复
csdnceshi60
℡Wang Yan Thanks man, you saved my day...
2 年多之前 回复
weixin_41568127
?yb? Thank you! In your step 5, I had "Copy only when installing" checked and that was my issue.
2 年多之前 回复
weixin_41568174
from.. Brilliant .. you solved my problems _
接近 3 年之前 回复
csdnceshi62
csdnceshi62 Making optional to framework solved my issue. But can you please explain me what is the behaviour of making framework optional ?
接近 3 年之前 回复
csdnceshi50
三生石@ This worked for me, thank you
接近 3 年之前 回复
csdnceshi78
程序go 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
大约 3 年之前 回复

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

csdnceshi68
local-host 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.
大约 4 年之前 回复

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

Hope that helps!

csdnceshi53
Lotus@ 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.
2 年多之前 回复
csdnceshi67
bug^君 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?
3 年多之前 回复
csdnceshi58
Didn"t forge Thanks. Your answer helped me much more and ofcourse NeverHopeless's also did :) Thanks you guys
接近 4 年之前 回复
weixin_41568208
北城已荒凉 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
接近 4 年之前 回复
weixin_41568196
撒拉嘿哟木头 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.
接近 4 年之前 回复

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.

weixin_41568196
撒拉嘿哟木头 This answer, along with your comment, saved me from getting insane. Ran into this issue with AuthenticationServices.framework, which requires iOS 12.
大约 2 年之前 回复
csdnceshi69
YaoRaoLov it's worked maybe the reason is some framework didn't run in simulator that's why
2 年多之前 回复
csdnceshi55
~Onlooker 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
2 年多之前 回复
weixin_41568208
北城已荒凉 Because UserNotifications framework requires iOS10
接近 3 年之前 回复
csdnceshi74
7*4 This works. Does anybody know why? Cuz some devices need this setting others do not.
大约 3 年之前 回复

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

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

csdnceshi69
YaoRaoLov 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.
接近 4 年之前 回复
csdnceshi65
larry*wei 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.
接近 4 年之前 回复

Add the framework in Embedded Binaries enter image description here

Then Clean and Build.

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.

csdnceshi75
衫裤跑路 I'm glad I kept scrolling through the answers. This fixed my problem. Thanks :)
大约 3 年之前 回复
共20条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐