这个崩溃是一个阻塞问题,我使用以下步骤来重现这个问题:

创建一个Cocoa Touch框架项目 添加一个swift文件和一个类Dog 为设备构建一个框架 在Swift中创建一个单视图应用程序 导入框架到应用程序项目 从ViewController中的框架实例化swift类 在设备上构建并运行应用程序

应用程序在启动时立即崩溃,这是控制台日志:

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?


当前回答

在Xcode 11中

我也面临着同样的问题

在“常规”选项卡>“框架、库和嵌入式内容”中更改“不要嵌入”仍然会导致相同的错误。

为我解决了什么是在构建阶段选项卡>嵌入框架部分添加框架

——更新

我观察到,在Xcode 11中运行时,在以前版本的Xcode中构建的项目中,嵌入框架部分不可用,请找到以下步骤来实现解决方案:

1:首先需要在Build Phases选项卡下添加New Copy Files Phase。

2:第二,将添加的阶段名称更改为Embed Frameworks

3:将目标更改为Frameworks。

4:添加发生错误的框架。

其他回答

我在iOS 9中遇到了同样的问题。x版本

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

我已经解决了这个问题,在链接框架和库UserNotifications.framework框架中将Required更改为Optional。

在我的案例中,解决方案是从嵌入式二进制文件中删除已编译的框架,这是工作空间中的一个独立项目,清理并重新构建它,最后重新添加到嵌入式二进制文件中。

仅仅将框架拖到项目中是不够的。这就像是在同一个球场,却找不到自己的孩子。遵循以下步骤:

1)创建框架

开发框架。 一旦你的开发完成,COMMAND+B构建你的框架,并确保你收到“构建成功”。

2)访问你的框架

一旦你的框架项目成功构建,你就可以在项目的Products文件夹中访问它了。

右键单击你的.framework,选择“显示在Finder中”。

3)在项目中放置框架

将. Framework从Finder窗口拖放到应用项目的“Framework”文件夹中。

4)为框架配置app项目

选择项目中的顶层

选择目标

转到“Build Phases”,然后是“Link Binary with Libraries”,确保你的框架包含了可选选项。

仍然在“构建阶段”,转到左上角并选择+按钮。在下拉菜单中选择“New Copy Files Phase”。

向下滚动到新的“复制文件”部分,并确保您将目标设置为“框架”。将子路径保留为空。然后点击左下角的+按钮。

您将看到您的项目层次结构。向下滚动到第三步中添加框架的“Frameworks”文件夹,或者在顶部的搜索栏中搜索它。选择你的框架,然后点击“添加”。

确保选择了“代码签入复制”,并包含了您的框架。

5)清洁,然后运行你的项目

司令部SHIFT键+ K 指挥部+ R

在嵌入式二进制文件中添加框架

然后清洁和建造。

对于Xcode中使用pod的任何项目或框架项目,避免动态库(dylb)不加载的一个简单方法是将pod文件设置为静态模式。要做到这一点,只需确保不要在pod文件中写入以下行。

use_frameworks!

一旦行从你保存的文件中删除,只需从控制台运行:

$ pod update