包括我在内的很多人都在尝试为 iOS 制作一种静态库框架来归档某种模块化.框架是执行此操作的最佳方法,但 Apple 并未提供此框架,并且解决方法效果不佳.
Many people including me trying to make a kind of Static Library framework for iOS to archive some kind of modularity. Framework is best way to do this, but it doesn't provided by Apple, and workarounds don't work well.
https://github.com/kstenerud/iOS-Universal-Framework/tree/master/Fake%20Framework/Templates
问题是静态库需要头文件,如果没有脚本,就不可能在不同项目的另一个位置引用项目上的头文件.并且脚本打破了 IDE 的文件管理抽象.
Problem is static library need header files, and it's impossible to reference header files on project at another location on different project without some script. And script breaks IDE's file management abstraction.
我怎样才能像使用方便的模块方式一样使用静态库项目?(只需将项目拖入另一个项目即可完成嵌入)
How can I use static library project like a convenient module manner? (just dragging project into another project to complete embedding)
解决方案.
PUBLIC_HEADERS_FOLDER_PATH
)YourLibrary.framework/Headers
.我使用 ${PRODUCT_NAME}.framework/Headers
与项目名称自动同步.PUBLIC_HEADERS_FOLDER_PATH
)YourLibrary.framework/Headers
. I have used ${PRODUCT_NAME}.framework/Headers
for automatic syncing with project name.现在所有头文件都将像 Framework 一样形成并与产品二进制文件一起复制.IDE 会将它们作为一个单元复制到某个临时文件夹中,例如应用程序的构建文件夹.所以引用app项目可以自动使用headers.
Now all header files will be formed like Framework and copied with product binary. IDE will copy all of them as a unit into some temporary folder like app's build folder. So referencing app project can use the headers automatically.
这是一个技巧.创建的目录结构不是真正的框架.因为它不包含任何二进制文件.然而,我们不需要真正的框架来归档这个功能.IDE 与没有任何二进制文件的框架一起工作.而且我不想在没有关于内部结构的文档的情况下破解 IDE.
This is a trick. The created directory structure is not real framework. Because it doesn't contain any binary. However we don't need real framework to archive just this functionality. IDE works with frameworks without any binary. And I don't want to hack IDE without documentation about internal structure.
这很好用,但是当您存档 时会遇到一些问题.发生这种情况是因为 Xcode4 在归档时表现得特别.这是解决方法.
This works well, however you'll experience some problem when you Archive. This happens because Xcode4 behaves specially when Archiving. Here's workaround.
SKIP_INSTALL = YES
在目标构建设置中.FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts"
.注意这个设置应该只为 Release
构建模式设置.SKIP_INSTALL = YES
in target build settings.FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts"
. Take care about this setting should be set only for Release
build mode.现在它会很好地存档.
在跨平台库的情况下,可以有多个平台的多个项目.但有时 Xcode 会在编译成功的情况下将某些产品显示为红色.
At the case of cross platform library, there can be many projects for many platforms. But sometime Xcode will show some product as red color even it compiled successfully.
这是 Xcode 的一个错误.IDE 显示取决于 Project 构建设置的 SDKROOT
.因此,如果您在 Target 上设置不同的 SDKROOT
,它将不起作用.您可以检查更改 Project 构建设置的 SDKROOT
后产品会变成黑色.有关详细信息,请参阅此 Open Radar 条目.
This is a bug of Xcode. IDE display depends SDKROOT
of Project build setting. So if you set the SDKROOT
differently on Target, it won't work. You can check the the product will become black color after changing the SDKROOT
of the Project build setting. See this Open Radar entry for details.
http://openradar.appspot.com/9636211
如果您希望修复此错误,请将此报告给 苹果的雷达.重复的错误会引起 Apple 的注意.只需复制 &粘贴我的报告:)
If you wish to fix this bug, please report this to Apple's Radar. Duplicated bugs will make attention of Apple. Just copy & paste my report :)
这篇关于在 Xcode4 中将静态库项目作为模块管理,如 iOS 项目上的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!