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


当前回答

删除派生数据为我保存了它

其他回答

对我来说,这就是解决方案,经过许多小时的搜索!!

出于某种原因,在Swift 2.3自定义框架的开发过程中,Xcode 8从项目中删除了DYLIB_INSTALL_NAME_BASE设置。pbxproj文件。稍微进入Build Settings / Dynamic Library Install Name Base设置回到@rpath就修复了它。

(来自https://forums.developer.apple.com/thread/4687)

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

构建框架

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

包括框架

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

我认为没有固定的方法来解决这个问题,因为它可能是由不同的原因引起的。我上周也有这个问题,我不知道什么时候以及究竟是什么原因导致了这个问题,只有当我用Xcode在模拟器上运行它或试图将它安装到手机上时,它才会报告这种错误,但当我用react-native run-ios与终端运行它时,没有问题。

我检查了网上发布的所有方法,比如更新证书,更改Xcode中的设置(上面提到的所有方法),实际上Xcode中的所有设置都已经按照要求设置了,没有一种方法适合我。直到今天早上,当我删除吊舱并重新安装时,错误终于在一周后出现。如果你也在使用cocoapod,然后错误就出现了,没有任何特定的原因,也许你可以试试我的方法。

看看我的cocoapods版本。 如果有可用的新版本,请更新它。 转到项目文件夹,删除Podfile。锁,Pods文件,项目xcworkspace。 运行pod安装

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

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