如何导出“脂肪"Cocoa Touch Framework(用于模拟器和设备)? [英] How to export "fat" Cocoa Touch Framework (for Simulator and Device)?

查看:18
本文介绍了如何导出“脂肪"Cocoa Touch Framework(用于模拟器和设备)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Xcode 6,我们可以创建自己的动态 Cocoa 框架.

因为:

  • 模拟器仍然使用32-bit

  • <块引用>

    自 2015 年 6 月 1 日起提交到 App Store 的应用更新必须包含 64 位支持并使用 iOS 8 SDK 构建(,但不是重复的.


    更新:

    我发现了一个肮脏的黑客"对于这种情况.请参阅我的下面的答案.如果有人知道更方便的方法 - 请告诉我!

    解决方案

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

    TLDR;

    目前Xcode没有自动导出通用fat框架的工具,所以开发者必须手动使用lipo工具.另外根据这个雷达,在提交给作为框架消费者的AppStore开发者之前也必须使用lipo 从框架中剥离模拟器切片.

    后面有更长的答案

    <小时>

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

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

    这是来自 Apple 开发者论坛主题的长引用(有一点我的标记)导出应用程序嵌入式框架:

    <块引用>

    从框架项目中导出框架的正确方法是什么?

    目前唯一的方法就是你所做的:

    • 为模拟器和 iOS 设备构建目标.
    • 导航到该项目的 Xcode 的 DerivedData 文件夹,并将两个二进制文件整合到一个框架中.但是,当您在 Xcode 中构建框架目标时,请确保将目标设置仅构建活动架构"调整为否".这将允许 Xcode 为多种二进制类型(arm64、armv7 等)构建目标.这就是为什么它可以在 Xcode 中运行,但不能作为独立的二进制文件运行.

    • 此外,您还需要确保将方案设置为发布版本,并根据发布版本构建框架目标.如果您仍然遇到未加载库的错误,请检查框架中的代码片段.

    • 使用 lipo -info MyFramworkBinary 并检查结果.

    lipo -info MyFrameworkBinary

    结果是i386 x86_64 armv7 arm64

    • 现代通用框架将包含 4 个切片,但可能包含更多:i386 x86_64 armv7 arm64如果您至少没有看到这 4 个,那可能是因为 Build Active Architecture 设置.

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

    这就是 Carthage 使用 lipo 的方式Realm 使用 lipo.

    <小时>

    重要细节

    有雷达:Xcode 6.1.1 &6.2: 包含模拟器切片的 iOS 框架无法提交到 App Store 和关于它的长时间讨论 Realm#1163Carthage#188 结束在特殊解决方法中:

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

    Carthage 有特殊代码:CopyFrameworks 和相应的文档:

    <块引用>

    此脚本解决了由通用二进制文件触发的 App Store 提交错误.>

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

    <块引用>

    在归档通用二进制文件时需要执行此步骤来解决 App Store 提交错误.

    还有好文章:从 Xcode 中的动态库中去除不需要的架构.

    我自己使用了 Realm 的 strip-frameworks.sh,它完全适用于我,无需任何修改,当然任何人都可以从头开始编写一个.

    <小时>

    我推荐阅读我的主题的链接,因为它包含这个问题的另一个方面:代码签名 - 创建 iOS/OSX 框架:是否有必要在分发给其他开发人员之前对其进行协同设计?

    With Xcode 6 we get ability to create own Dynamic Cocoa Frameworks.

    Because of:

    • Simulator still use 32-bit library

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

    We have to make fat library to run project on devices and simulators. i.e. support both 32 and 64 bit in Frameworks.

    But I didn't find any manuals, how to export universal fat Framework for future integration with other projects (and share this library with someone).

    Here is my steps to reproduce:

    1. Set ONLY_ACTIVE_ARCH=NO in the Build Settings

    2. Add support armv7 armv7s arm64 i386 x86_64 to Architectures (for sure)

    1. Build Framework and open it in Finder:

    1. Add this framework to another project

    Actual result:

    But in the end I still have problem with running project with this framework on devices and simulator at once.

    • if I take framework from Debug-iphoneos folder - it works on devices and gets error on simulators: ld: symbol(s) not found for architecture i386

        xcrun lipo -info CoreActionSheetPicker
      

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

    • if I take framework from Debug-iphonesimulator folder - it works on simulators. and I have error on device: ld: symbol(s) not found for architecture arm64

        xcrun lipo -info CoreActionSheetPicker
      

      Architectures in the fat file: CoreActionSheetPicker are: i386 x86_64

    So, how to create a dynamic framework that works on devices and simulators?

    This answer related to Xcode 6 iOS Creating a Cocoa Touch Framework - Architectures issues but it's not duplicate.


    Update:

    I found a "dirty hack" for this case. See my answer below. If someone knows more convenient way - please, let me know!

    解决方案

    The actuality of this answer is: July 2015. It is most likely that things will change.

    TLDR;

    Currently Xcode does not have tools for automatic export of universal fat framework so developer must resort to manual usage of lipo tool. Also according to this radar before submission to AppStore developer who is framework's consumer also must use lipo to strip off simulator slices from a framework.

    Longer answer follows


    I did similar research in the topic (the link at the bottom of the answer).

    I had not found any official documentation about distribution of so my research was based on exploration of Apple Developer Forums, Carthage and Realm projects and my own experiments with xcodebuild, lipo, codesign tools.

    Here's long quote (with a bit of markup from me) from Apple Developer Forums thread 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.

    This describes process pretty much the same as @skywinder did it in his answer.

    This is how Carthage uses lipo and Realm uses lipo.


    IMPORTANT DETAIL

    There is radar: Xcode 6.1.1 & 6.2: iOS frameworks containing simulator slices can't be submitted to the App Store and a long discussion around it on Realm#1163 and Carthage#188 which ended in special workaround:

    before submission to AppStore iOS framework binaries must be stripped off back from simulator slices

    Carthage has special code: CopyFrameworks and corresponding piece of documentation:

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

    Realm has special script: strip-frameworks.sh and corresponding piece of documentation:

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

    Also there is good article: Stripping Unwanted Architectures From Dynamic Libraries In Xcode.

    I myself used Realm's strip-frameworks.sh which worked for me perfectly without any modifications though of course anyone is free to write a one from scratch.


    The link to my topic which I recommend to read because it contains another aspect of this question: code signing - Creating iOS/OSX Frameworks: is it necessary to codesign them before distributing to other developers?

    这篇关于如何导出“脂肪"Cocoa Touch Framework(用于模拟器和设备)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆