我试图创建一个基本的OS X框架,现在我刚刚创建了一个测试框架:TestMacFramework.framework,我试图将它导入到一个全新的OS X应用程序项目。

我已经构建了.framework文件并将其导入到新项目中,框架链接正常,我可以引用我添加到框架构建阶段部分的公共头文件。

然而,当我尝试运行容器应用程序时,我得到以下错误:

dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
  Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
  Reason: image not found

在谷歌了一下之后,我意识到我需要在我的容器应用程序构建阶段添加一个复制文件部分,所以我已经这样做了,并像这样设置它…

然而,我仍然得到运行时错误。显然我在这里做错了什么,但是苹果开发者库的资源引用了Xcode 2,所以不是很有帮助!

我错过了什么?

更新:

我可以在构建日志中看到我的TestMacFramework.framework被复制到.app contents/frameworks目录中,但它没有被安装到HD上的Library/ frameworks目录中

更新2:

如果我手动将TestMacFramework.framework复制到Library/Frameworks目录中,构建链接是正确的


当前回答

对我来说,由于某种原因xCode(到目前为止12.5)决定我的通知服务扩展目标不应该有正确的框架路径。我怀疑这发生在我从xCode 12.1更新到12.5之后。

所以我得到了与我的一个内部框架相关的相同错误。要解决这个问题,请执行以下操作:

go to Project's General Tab Select your target (in my case it was Notification Service Extension Target) Make sure that Framework and Libraries section contains your missing framework. I've left it Embed Without Signing in my NSE Target, but it is also was added with Embed & Sign to my primary app target Keep your target selected and switch to Build Settings tab There in a search bar enter LD_RUNPATH_SEARCH_PATHS (make sure that All possible settings will be displayed and not just Basic) You will see Runpath Search Paths and it was empty for me. Add 3 following values there: $(inherited) @executable_path/Frameworks @executable_path/../../Frameworks

这对我很有帮助。

其他回答

None of these issues solved this for me. The problem in the end was pretty easy. It looks like its a pretty major Xcode bug which I have logged the problem and fix under Apple bug: 29820370. If you are struggling (as it seems like there are several pages of problems similar to this ) then it would be great if you can raise a bug on bug reporter: https://bugreport.apple.com/ and reference the bug I raised to gain visibility. I want to make Xcode back into the pleasure that it was before - and this is something I am sure Xcode should have fixed itself.

下面是解决方案: 1. 打开钥匙串-去苹果全球开发者证书。 2. 双击它 3.将权限级别从“始终信任”更改为使用“系统默认” 4. 保存并关闭 5. 重新启动Xcode,清理并构建项目,它应该消失了。

下面是正确设置的截图: 希望这能有所帮助!

我在Xcode 13 beta版中使用uniformtypeidentifier .framework遇到了这个问题。该应用程序无法在低于13的iOS版本上运行。 下面的方法解决了这个问题:

去目标->构建阶段->链接二进制与库->添加框架->添加状态为“可选” 以上方法对我来说非常有效!希望这能有所帮助!

这对我来说很简单,我只是把我的框架添加到我的app目标下的嵌入式二进制文件中

我只在真正的设备(iPhone SE)上运行时遇到过这个问题。在模拟器项目工作如预期。

我尝试了所有的修复从这个线程和从这里。 这些对我都没用。

对我来说,重启iPhone后问题就解决了。

我做了:

清洁构建文件夹, 干净的衍生数据, 从设备上删除app 重新启动设备

最终成功了。:)

如果其他解决方案都失败了,不要忘记尝试一下。

我遇到了同样的问题,但公认的解决方案并不适合我。相反,解决方案是修改框架的安装名称。

原帖子中的错误是:

dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
  Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
  Reason: image not found

注意Library未加载后的第一个路径。框架是从绝对路径加载的。这个路径来自框架的安装名(有时称为rpath),可以使用以下方法检查:

otool -D MyFramework.framework/MyFramework

当一个框架被嵌入到一个应用程序中时,这个路径应该是相对的,并且是这样的形式:@rpath/MyFramework.framework/MyFramework。如果你的框架的安装名称是一个绝对路径,它可能不会在运行时被加载,并且会产生类似上面的错误。

解决方案是修改安装名称:

install_name_tool -id "@rpath/MyFramework.framework/MyFramework" MyFramework.framework/MyFramework 

有了这个更改,我不再得到错误