Managing Static Library project as a module like Framework on iOS project in Xcode4(在 Xcode4 中将静态库项目作为模块管理,如 iOS 项目上的框架)
问题描述
包括我在内的很多人都在尝试为 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 文件夹路径.(定义名称 =
PUBLIC_HEADERS_FOLDER_PATH
) - 将其设置为
YourLibrary.framework/Headers
.我使用${PRODUCT_NAME}.framework/Headers
与项目名称自动同步. - 转到 Build Phases 并找到 Copy Headers 步骤.
- 将所有必需的标题移动到 Public 窗格.
- Goto Project or Target's Build Settings.
- Find Public Headers Folder Path. (definition name =
PUBLIC_HEADERS_FOLDER_PATH
) - Set it as
YourLibrary.framework/Headers
. I have used${PRODUCT_NAME}.framework/Headers
for automatic syncing with project name. - Goto Build Phases and find Copy Headers step.
- Move all required headers to Public pane.
现在所有头文件都将像 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
构建模式设置.
- For each embedded library project,
SKIP_INSTALL = YES
in target build settings. - For final product project,
FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts"
. Take care about this setting should be set only forRelease
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 项目上的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Xcode4 中将静态库项目作为模块管理,如 iOS 项目上的框架
基础教程推荐
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- 更改 UITableView 部分标题的颜色 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01