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

创建一个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或更新版本:

导航到目标的设置并选择General。

向下滚动到框架、库和嵌入式内容。 如有必要,请确保为“嵌入”选项选择了“嵌入&签名”或“嵌入不签名”值。

其他回答

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

如果有人仍然遇到这个问题,尽管遵循了许多其他答案中概述的所有步骤,您可能需要撤销并重新创建您的代码签名证书,如下所示:

https://developer.apple.com/library/ios/qa/qa1886/_index.html

如果你也得到了这个控制台除了日志在回答:

原因:没有找到合适的图像。确实发现:

可能你的框架是为更高的部署版本构建的,而不是你的应用程序。例如,应用程序是为iOS 12构建的,框架是为iOS 14构建的,而你在iOS 12设备上运行。

尝试在构建设置中将ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES(在早期的xcode版本中:嵌入式内容包含Swift代码)从NO更改为YES。

如果您正在使用第三方框架,并使用Cocoapods作为依赖管理器,请尝试执行pod安装来刷新您的pod。

这个崩溃发生在我正在使用的第三方库上,所以很高兴上面的解决方案对我有用,希望它对你有用!