我试图创建一个基本的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 11 +]

唯一要做的就是将框架添加到目标应用程序的General选项卡中的General->Frameworks, Libraries And Embedded Content部分。

确保你选择了“嵌入&签名”选项。

[Xcode v6 -> Xcode v10]

唯一要做的就是将框架添加到目标应用程序General选项卡的Embedded binaries部分。

其他回答

如果你不小心重置了你的钥匙链,这可能是由于在钥匙链中丢失了苹果证书。我遵循这个方法来解决我的问题。

我遇到了同样的问题,并通过重新下载WWDR(苹果全球开发者关系认证机构)来解决。 从这里下载:http://developer.apple.com/certificationauthority/AppleWWDRCA.cer

Xcode 11:

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

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

所以我设法让它工作了,只要你有正确的指令,这很简单。我所寻找的是一个“私有”框架,它存在于App包中,而不是被写入系统库文件夹。

构建框架

添加目标以创建Cocoa Framework 在目标“构建设置”中将“安装目录”配置为“@executable_path/../Frameworks” 构建库,并从存档或产品目录中访问.framework

包括框架

将创建的。framework文件拖到Xcode项目中,确保勾选“复制文件到目录” 在包含应用程序的目标中,添加一个新的“Copy File Build Phase” 将“目标”设置为“框架” 拖入已创建的.framework

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 8,一些陈旧的产品将从派生的数据文件夹中删除参考这个解决方案。

苹果:在macOS 10.12及以后版本中,Xcode会清理陈旧的派生数据、预编译的头文件和模块缓存。(23282174)

Xcode构建系统支持旧文件删除某些类型的构建构件,这些构件在以前的构建中产生,但已经从项目中删除了。

根据作者的想法,我从我的案例中找到了这个构建日志。

Remove stale build products

/bin/rm -rf /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks/AliyunVodPlayerSDK.framework
/bin/rmdir /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks

在创建新的复制文件阶段并将目标陈旧框架复制到框架目标之后,上述删除日志在重建后消失。

澄清一下我的情况和原因,希望对大家有所帮助。