ios - 如何导出 "fat"Cocoa Touch Framework(用于模拟器和设备)?

标签 ios xcode cocoa-touch frameworks ios-universal-framework

借助 Xcode 6,我们能够创建自己的动态 Cocoa Frameworks

enter image description here

因为:

  • 模拟器仍然使用32位

  • >

    beginning June 1, 2015 app updates submitted to the App Store must include 64-bit support and be built with the iOS 8 SDK (developer.apple.com)

我们必须制作胖库才能在设备和模拟器上运行项目。即在框架中支持 32 位和 64 位。

但我没有找到任何手册,如何导出通用胖框架以便将来与其他项目集成(并与某人共享此库)。

这是我重现的步骤:

  1. Build Settings中设置ONLY_ACTIVE_ARCH=NO

    enter image description here

  2. 将支持 armv7 armv7s arm64 i386 x86_64 添加到 Architectures(肯定)

enter image description here

  1. 构建框架并在 Finder 中打开它:

enter image description here enter image description here

  1. 将此框架添加到另一个项目

实际结果:

但最后我仍然无法同时在设备和模拟器上使用此框架运行项目。

  • 如果我从 Debug-iphoneos 文件夹中获取框架 - 它可以在设备上运行 并在模拟器上出现错误:ld: symbol(s) not found for architecture i386

      xcrun lipo -info CoreActionSheetPicker
    

    Architectures in the fat file: CoreActionSheetPicker are: armv7 armv7s arm64

  • 如果我从 Debug-iphonesimulator 文件夹中获取框架 - 它可以在模拟器上运行。我在设备上有错误:ld: symbol(s) not found for architecture arm64

      xcrun lipo -info CoreActionSheetPicker
    

    Architectures in the fat file: CoreActionSheetPicker are: i386 x86_64

那么,如何创建一个适用于设备和模拟器的动态框架?

此答案与 Xcode 6 iOS Creating a Cocoa Touch Framework - Architectures issues 有关但它不是重复的。


更新:

我发现了这个案例的“肮脏黑客”。看我的answer below . 如果有人知道更方便的方法 - 请告诉我!

最佳答案

这个答案的实际情况是:2015 年 7 月。情况很可能会发生变化。

TLDR;

目前 Xcode 没有自动导出通用 fat 框架的工具,所以开发者必须求助于手动使用 lipo 工具。也根据this radar在提交给作为框架消费者的 AppStore 开发人员之前,还必须使用 lipo 从框架中剥离模拟器切片。

下面是更长的答案


我对该主题进行了类似的研究(答案底部的链接)。

我没有找到任何关于分发的官方文档,所以我的研究基于对 Apple Developer Forums、Carthage 和 Realm 项目的探索以及我自己对 xcodebuildlipo代码设计工具。

这是来自 Apple 开发者论坛主题的长引用(带有我的一些标记)Exporting app with embedded framework :

What is the proper way to export a framework from a framework project?

Currently the only way is exactly what you have done:

  • Build the target for both simulator and iOS device.
  • Navigate to Xcode's DerivedData folder for that project and lipo the two binaries together into one single framework. However, when you build the framework target in Xcode, make sure to adjust the target setting 'Build Active Architecture Only' to 'NO'. This will allow Xcode to build the target for multiple binarty types (arm64, armv7, etc). This would be why it works from Xcode but not as a standalone binary.

  • Also you'll want to make sure the scheme is set to a Release build and build the framework target against release. If you are still getting a library not loaded error, check the code slices in the framework.

  • Use lipo -info MyFramworkBinary and examine the result.

lipo -info MyFrameworkBinary

Result is i386 x86_64 armv7 arm64

  • Modern universal frameworks will include 4 slices, but could include more: i386 x86_64 armv7 arm64 If you don't see at least this 4 it coud be because of the Build Active Architecture setting.

这描述的过程与@skywinder 在他的回答中所做的几乎相同。

这就是Carthage uses lipoRealm uses lipo .


重要细节

有雷达:Xcode 6.1.1 & 6.2: iOS frameworks containing simulator slices can't be submitted to the App Store并在 Realm#1163 上围绕它进行了长时间的讨论和 Carthage#188以特殊的解决方法结束:

在提交到 AppStore 之前,必须从模拟器切片中剥离 iOS 框架二进制文件

迦太基有特殊代码:CopyFrameworks以及相应的文档:

This script works around an App Store submission bug triggered by universal binaries.

Realm 有特殊的脚本:strip-frameworks.sh以及相应的文档:

This step is required to work around an App Store submission bug when archiving universal binaries.

还有好文章:Stripping Unwanted Architectures From Dynamic Libraries In Xcode .

我自己使用了 Realm 的 strip-frameworks.sh,它无需任何修改就可以完美地工作,当然任何人都可以自由地从头开始编写一个。


我推荐阅读我的主题的链接,因为它包含此问题的另一个方面:代码签名 - Creating iOS/OSX Frameworks: is it necessary to codesign them before distributing to other developers?

关于ios - 如何导出 "fat"Cocoa Touch Framework(用于模拟器和设备)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29634466/

相关文章:

iphone - 如何获取 JSON 值?

swift - 订购 Firebase 数据库,然后使用 Xcode 迭代并更新项目

objective-c - 将 Delegate 设置为放置在 Xib 中的 NSImageView 的子类

iphone - 通过 UITableView 设置菜单

ios - requestInterstitialAdPresentation 只工作一次

ios - 有什么方法可以在 xcode 中以十六进制显示 plist 数值吗?

ios - 在 iOS 中构建高级均衡器

ios - AVAssetWriter AVVideoExpectedSourceFrameRateKey(帧率)被忽略

ios - 在 Xcode/lldb 中移动执行点

objective-c - 对按钮xcode视而不见的函数