我试图创建一个基本的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目录中,构建链接是正确的


当前回答

I found that this issue was related only to the code signing and certificates not the code itself. To verify this, create the basic single view app and try to run it without any changes to your device. If you see the same error type this shows your code is fine. Like me you will find that your certificates are invalid. Download all again and fix any expired ones. Then when you get the basic app to not report the error try your app again after exiting Xcode and perhaps restarting your mac for good measure. That finally put this nightmare to an end. Most likely this has nothing to do with your code especially if you get Build Successful message when you try to run it. FYI

其他回答

唯一对我有用的是:

目标>构建阶段> [CP]嵌入Pods框架 取消勾选“在生成日志中显示环境变量”和“仅在安装时运行脚本”

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

当尝试Xcode 9测试版并返回到Xcode 8时,出现了问题。对目标进行简单的Clean就解决了这个问题。

Xcode 11:

在Xcode 11中将框架添加到通用->框架,库和嵌入式内容

添加后,确保你选择嵌入和签名选项

对我来说,由于某种原因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

这对我很有帮助。