简体   繁体   English

具有iphoneos和iphonesimulator体系结构的iOS通用框架

[英]iOS universal framework with iphoneos and iphonesimulator architectures

xcodebuild can build a project with sdk set to either iphoneos or iphonesimulator but not both, so in order to generate a framework containing armv7 arm64 and i386 x86_64 architectures, I have to run xcodebuild twice and then use lipo to combine all the architectures into 1 universal binary. xcodebuild可以构建将sdk设置为iphoneosiphonesimulator但不能同时设置两者的项目,因此,要生成包含armv7 arm64i386 x86_64体系结构的框架,我必须运行两次xcodebuild ,然后使用lipo将所有体系结构组合为1个通用二进制 I see commercial framework that does this but it result in an incorrect info.plist file because it has a field, CFBundleSupportedPlatforms and all signs point to it only containing 1 value, eg, CFBundleSupportedPlatforms = ( "iPhoneSimulator" ) . 我看到执行此操作的商业框架,但是它导致一个错误的info.plist文件,因为它具有一个字段CFBundleSupportedPlatforms并且所有符号都指向它仅包含1个值,例如CFBundleSupportedPlatforms = ( "iPhoneSimulator" )

Seems like lipo shouldn't be used in this manner because it isn't officially supported by xcodebuld . 似乎不应该以这种方式使用lipo ,因为xcodebuld并未正式支持xcodebuld Is there a better way to build a framework to contain all architectures? 有没有更好的方法来构建包含所有体系结构的框架?

I follow the question, but I suppose I am a bit puzzled why you want to unnecessarily bloat a single .framework with simulator-only i386 and x84_64 slices that are really only relevant to your development builds. 我遵循了这个问题,但是我想我有些困惑,为什么您要不必要地使用仅模拟器的i386和x84_64切片来膨胀一个.framework ,而这些切片实际上仅与您的开发版本相关。 Would you by chance be wanting to distribute a framework to other developers and want to make it work on simulator as well as device? 您是否会偶然想将框架分发给其他开发人员,并希望使其在模拟器以及设备上都能正常工作?

If so, you are on the right track with using lipo to join the thin binaries for device together or to join the thin binaries for simulator together, but shouldn't be trying to spawn one single device and simulator framework. 如果是这样,那么使用lipo将设备的精简二进制文件连接在一起或将模拟器的精简二进制文件连接在一起是正确的,但是不应尝试生成单个设备和仿真器框架。 Apple's own use of SDKs and Frameworks serves as the guide here. Apple自己使用的SDK和Framework充当此处的指南。 Within Xcode, there are two different platform SDKs -- iPhoneOS.platform and iPhoneSimulator.platform that contain the SDKs with only the slices for the relevant target architectures: 在Xcode中,有两个不同的平台SDK – iPhoneOS.platform和iPhoneSimulator.platform,其中包含SDK,其中仅包含相关目标体系结构的切片:

Xcode的平台选项

You can drill into each of these folders and find the UIKit frameworks do indeed follow the per-platform idea and are conditionally linked based on the SDK that is in use: 您可以深入研究这些文件夹中的每个文件夹,并发现UIKit框架确实遵循每个平台的想法,并且根据使用的SDK有条件地进行了链接:

UIKit Lipo

I'd further guess that you wanted to have one universal, all-architectures framework so that consuming developers didn't have to remember to swap out one .framework file for another depending on how they were compiling the app. 我会进一步猜测您希望拥有一个通用的,全架构的框架,这样,使精打细算的开发人员不必记住将一个.framework文件换成另一个.framework文件,这取决于他们如何编译应用程序。 The great news is that you can use conditional linking flags to be able to affect this without needing to do file-system swaps! 好消息是,您可以使用条件链接标志来实现此目的,而无需执行文件系统交换!

As folks adopt your library, part of the setup should be to use conditional linking -- Within the OTHER_LINKER_FLAGS option you can have per-configuration (Debug, Release, Ad-Hoc, etc.) build settings and can also have per-Architecture or per-SDK specific settings too: 当人们采用您的库时,部分设置应该是使用条件链接-在OTHER_LINKER_FLAGS选项中,您可以按配置进行配置(调试,发布, OTHER_LINKER_FLAGS等),也可以按架构进行配置每个SDK的特定设置:

其他链接器标志

To get access to these SDK-specific settings you'll need to click the + next to each of your build configurations where you want to custom tailor framework linking. 要访问这些特定于SDK的设置,您需要单击要自定义定制框架链接的每个构建配置旁边的+。 You can then select the appropriate SDKs from the dropdown list and add your linker flags for each of the two target frameworks. 然后,您可以从下拉列表中选择适当的SDK,并为两个目标框架中的每一个添加链接器标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM