xcode 使用自定义框架时出现“找不到图像”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20092886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:19:13  来源:igfitidea点击:

"image not found" Error while using Custom FrameWork

objective-cxcodemacoscocoa

提问by Midhun MP

I created my own framework for one of my cocoa application. I added that framework to my project and called a method from that framework. When I tried to run my application it crashed:

我为我的可可应用程序之一创建了自己的框架。我将该框架添加到我的项目中,并从该框架调用了一个方法。当我尝试运行我的应用程序时它崩溃了:

Crash Log:

崩溃日志:

dyld: Library not loaded: @rpath/MMP.framework/Versions/A/MMP
  Referenced from: /Users/Midhun/Library/Developer/Xcode/DerivedData/MMPTest-ccvjtgedqkcftchapjehhwjbaqdq/Build/Products/Debug/MMPTest.app/Contents/MacOS/MMPTest
  Reason: image not found

What I have done:

我做了什么:

FrameWork:

框架:

  • I added my header file in public section
  • 我在公共部分添加了我的头文件

Public Header

公共标题

  • I added the paths of Deployment and Linkinglike:
  • 我添加了部署的路径,Linking例如:

Paths

路径

  • I build the project and I got my framework ready (Pretty cool till here).
  • 我构建了项目并准备好了我的框架(直到这里都非常酷)。

Project:

项目:

  • I added that framework to FrameWorksfolder under my Project's root directory.
  • I added the framework under Link Binary With LibrariesSection
  • I changed the path of Linking like: Changed Path
  • 我将该框架添加到FrameWorks我的项目根目录下的文件夹中。
  • 我在Link Binary With Libraries节下添加了框架
  • 我改变了链接的路径,如: 改变路径

Platform Details:

平台详情:

Xcode: 4.6.2
OS X : 10.8

What I have tried (After the crash)

我尝试过的(崩溃后)

  • When I get this issue, I checked with otool. It shows the paths like:
  • 当我遇到这个问题时,我检查了otool. 它显示的路径如下:

otool

工具

But I couldn't fix the issue, yet. Please help me, thanks in advance.

但我还不能解决这个问题。请帮助我,提前致谢。

回答by Parag Bafna

Set framework installation directory to @executable_path/../Frameworks

将框架安装目录设置为 @executable_path/../Frameworks

enter image description here

在此处输入图片说明

Now add copy files in your build phase, set destination to Frameworks. click on your target, then on Editor(menu bar) --> Add build phase--> Add Copy Files Build Phase

现在在构建阶段添加复制文件,将目标设置为 Frameworks. 单击您的目标,然后单击编辑器(菜单栏)-->添加构建阶段-->添加复制文件构建阶段

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by aToz

I've encountered the same issue and this is how I have solved it,

我遇到了同样的问题,这就是我解决它的方法,

For my case, custom Framework is in Swiftand My project is in Objective c

就我而言,自定义框架在Swift 中,而我的项目在目标 c 中

Follow the following steps,

请按照以下步骤操作,

  1. Go the Project Navigator
  2. Select the Targets, go the Generaltab
  3. Find Embedded Binariesdrag the custom framework. Find the flow in the below-mentioned imageenter image description here
  4. Check if the Framework is added to the Linked Frameworks and Libraries(ref the image)List item
  5. NOTE: In my case it was added to Linked Frameworks and Libraries, go a head and removeit
  6. Last step, find the flag Always embed swift embedded librariesin "Build settings" and turn it to "YES" (ref the image)
  1. 转到项目导航器
  2. 选择Targets,转到General选项卡
  3. Find Embedded Binaries拖动自定义框架。在下面提到的图像中找到流程在此处输入图片说明
  4. 检查框架是否已添加到链接的框架和库中(参考图片)项目清单
  5. 注意:在我的例子中,它被添加到Linked Frameworks and Libraries,去删除
  6. 最后一步,在“构建设置”中找到标记Always embed swift embedding libraries并将其变为“YES”(参考图片)

enter image description here

在此处输入图片说明

I hope this helps.

我希望这有帮助。