将静态库项目作为 Xcode4 中 iOS 项目上的框架等模块进行管理

发布于 2024-11-16 06:39:25 字数 513 浏览 3 评论 0原文

包括我在内的许多人都试图为 iOS 制作一种静态库框架来归档某种模块化。框架是执行此操作的最佳方法,但 Apple 不提供该框架,并且解决方法效果不佳。

https://github.com/kstenerud/iOS-Universal -Framework/tree/master/Fake%20Framework/Templates

  1. 无法从构建阶段的链接选项卡引用假框架。
  2. 真正的框架需要修改系统设置。而且每个部分仍然不能顺利工作。

问题是静态库需要头文件,并且如果没有一些脚本,就不可能在不同项目的另一个位置引用项目上的头文件。并且脚本打破了 IDE 的文件管理抽象。

如何像方便的模块方式一样使用静态库项目? (只需将项目拖入另一个项目即可完成嵌入)

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

  1. Fake framework cannot be referenced from linking tab in Build Phases.
  2. Real framework needs modification of system setting. And still not work smoothly on every parts.

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半﹌身腐败 2024-11-23 06:39:25

此后我更新了模板以取消脚本目标。它现在从您的常规目标构建通用框架,因此您可以将其包含在工作区中或作为项目依赖项。

对于真正的框架目标,您只需将其添加到“Link Binary With Libraries”,它就会显示得很好。

使用假框架,Xcode无法识别目标类型,因此您需要手动添加链接命令。例如,假设您的框架名为 Foo:

  1. 展开框架项目的“产品”组,然后将“Foo.framework”拖到应用目标的“链接二进制文件与库”构建阶段。

  2. 在您的应用目标中,在构建设置中编辑“其他链接器标志”并添加:“-framework Foo”

任何不确定我们在说什么的人的框架模板链接:https://github.com/kstenerud/iOS-Universal-Framework

I've since updated the template to do away with the script target. It now builds the universal framework from your regular target, so you can include it in workspaces or as a project dependency.

With a real framework target, you can just add it to "Link Binary With Libraries", and it will show up fine.

With a fake framework, Xcode doesn't recognize the target type, so you need to add the link command manually. For example, assuming your framework is called Foo:

  1. Expand the "Products" group of your framework project, then drag "Foo.framework" into the "Link Binary With Libraries" build phase of your app target.

  2. In your app target, edit "Other Linker Flags" in the build settings and add: "-framework Foo"

Framework template link for anyone not sure what we're talking about: https://github.com/kstenerud/iOS-Universal-Framework

习ぎ惯性依靠 2024-11-23 06:39:25

解决方案。

  1. 转到项目目标构建设置
  2. 查找公共标头文件夹路径。 (定义名称 = PUBLIC_HEADERS_FOLDER_PATH
  3. 将其设置为 YourLibrary.framework/Headers。我已使用 ${PRODUCT_NAME}.framework/Headers 与项目名称自动同步。
  4. 转到构建阶段并找到复制标头步骤。
  5. 将所有必需的标头移至“公共”窗格。

现在,所有头文件都将像框架一样形成并与产品二进制文件一起复制。 IDE 会将它们作为一个单元复制到某个临时文件夹中,例如应用程序的构建文件夹。因此引用应用程序项目可以自动使用标题。

这是一个技巧。创建的目录结构不是真正的框架。因为它不包含任何二进制文件。然而,我们不需要真正的框架来归档此功能。 IDE 可与框架配合使用,无需任何二进制文件。而且我不想在没有有关内部结构的文档的情况下破解 IDE。


这很有效,但是您在存档时会遇到一些问题。。发生这种情况是因为 Xcode4 在存档时有特殊的行为。这是解决方法。

  1. 对于每个嵌入式库项目,目标构建设置中的SKIP_INSTALL = YES
  2. 对于最终产品项目,FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts"。请注意,此设置只能针对 Release 构建模式进行设置。

现在它会被很好地存档。


在跨平台库的情况下,可以有针对多个平台的多个项目。但有时 Xcode 会将某些产品显示为红色,即使它编译成功。

这是 Xcode 的一个错误。 IDE 显示取决于 Project 构建设置的 SDKROOT。因此,如果您在 Target 上设置不同的 SDKROOT,它将不起作用。您可以检查更改 Project 构建设置的 SDKROOT 后产品将变成黑色。有关详细信息,请参阅此开放雷达条目。

http://openradar.appspot.com/9636211

如果您想修复此错误,请将其报告给Apple 的雷达。重复的错误会引起苹果公司的注意。只需复制并粘贴我的报告:)

Solution.

  1. Goto Project or Target's Build Settings.
  2. Find Public Headers Folder Path. (definition name = PUBLIC_HEADERS_FOLDER_PATH)
  3. Set it as YourLibrary.framework/Headers. I have used ${PRODUCT_NAME}.framework/Headers for automatic syncing with project name.
  4. Goto Build Phases and find Copy Headers step.
  5. Move all required headers to Public pane.

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.

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.


This works well, however you'll experience some problem when you Archive. This happens because Xcode4 behaves specially when Archiving. Here's workaround.

  1. For each embedded library project, SKIP_INSTALL = YES in target build settings.
  2. For final product project, FRAMEWORK_SEARCH_PATHS = "${OBJROOT}/UninstalledProducts". Take care about this setting should be set only for Release build mode.

Now it'll be archived well.


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.

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

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文