`
dingdingfm
  • 浏览: 49664 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

Xcode设置 Architectures和Valid Architectures

    博客分类:
  • iOS
 
阅读更多
iPhone指令集

本文所讲的内容都是围绕iPhone的指令集(想了解ARM指令集的同学请点击这里),现在先说说不同型号的iPhone都使用的是什么指令集:

ARMv8/ARM64 = iPhone 5s, iPad Air, Retina iPad MiniARMv7s = iPhone 5, iPhone 5c, iPad 4ARMv7= iPhone 3GS, iPhone 4, iPhone 4S, iPod 3G/4G/5G, iPad, iPad 2, iPad 3, iPad MiniARMv6= iPhone, iPhone 3G, iPod 1G/2G

设置你想支持的指令集

Xcode中关于生成二进制包指令集相关的设置项有以下三个:
Architectures
官方文档说明:
Space-separated list of identifiers. Specifies the architectures (ABIs, processor models) to which the binary is targeted. When this build setting specifies more than one architecture, the generated binary may contain object code for each of the specified architectures.

改变以选项指定了工程将被编译成支持哪些指令集,支持指令集是通过编译生成对应的二进制数据包实现的,如果支持的指令集数目有多个,就会编译出包含多个指令集代码的数据包,造成最终编译的包很大。

Valid Architectures
官方文档说明:
Space-separated list of identifiers. Specifies the architectures for which the binary may be built. During the build, this list is intersected with the value of ARCHS build setting; the resulting list specifies the architectures the binary can run on. If the resulting architecture list is empty, the target generates no binary.

该编译项指定可能支持的指令集,该列表和Architectures列表的交集,将是Xcode最终生成二进制包所支持的指令集。

比如,你的Valid Architectures设置的支持arm指令集版本有:armv7/armv7s/arm64,对应的Architectures设置的支持arm指令集版本有:armv7s,这时Xcode只会生成一个armv7s指令集的二进制包。
Build Active Architecture Only

官方文档说明:


Boolean value. Specifies whether the product includes only object code for the native architecture.

该编译项用于设置是否只编译当前使用的设备对应的arm指令集。

当该选项设置成YES时,你连上一个armv7指令集的设备,就算你的Valid Architectures和Architectures都设置成armv7/armv7s/arm64,还是依然只会生成一个armv7指令集的二进制包。

当然该选项起作用的前提是你的Xcode必须成功连接了调试设备。如果你没有任何活跃设备,即Xcode没有成功连接调试设备,就算该设置项设置成YES依然还会编译Valid Architectures和Architectures指定的二进制包。

通常情况下,该编译选项在Debug模式都设成YES,Release模式都设成NO。
说明

    指令集都是可以向下兼容的

比如,你的设备是armv7s指令集,那么它也可以兼容运行比armv7s版本低的指令集:armv7、armv6

    xcode对armv6指令集的支持

Xcode4.5起不再支持armv6,Xcode4.5的release notes中明确指出:


ChangesGeneral: iOSThis version of Xcode does not generate armv6 binaries. 12282156The minimum deployment target is iOS 4.3. 12282166

如何选择支持的指令集

如果你的软件对安装包大小非常敏感,你可以减少安装包中的指令集数据包,而且这能达到立竿见影的效果。

我们的项目之前支持的指令集是armv7/armv7s,后来改成只支持armv7后,比原来小了10MB左右。目前AppStore上的一些知名应用,比如百度地图、腾讯地图通过反汇编工具查看后,也都只支持armv7指令集。

根据向下兼容原则,armv7指令集的应用是可以正常在支持armv7s/arm64指令集的机器上运行的。

不过对于armv7s/arm64指令集设备来说,使用运行armv7应用是会有一定的性能损失,不过这种损失有多大缺乏权威统计数据,个人认为是不会影响用户体验的。
参考文档



目前ios的指令集有以下几种:

1,armv6,支持的机器iPhone,iPhone2,iPhone3G及对应的iTouch

2,armv7,支持的机器iPhone4,iPhone4S

3,armv7s,支持的机器iPhone5,iPhone5C

4,arm64,支持的机器:iPhone5S

机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S的,只是效率没那么高而已~

========================

Architecture : 指你想支持的指令集。

Valid architectures : 指即将编译的指令集。

Build Active Architecture Only : 只是否只编译当前适用的指令集。

========

现在是2014年初,其实4和4S的用户还是蛮多的,而iphone3之类的机器几乎没有了,所以我们的指令集最低必须基于armv7.

因此,Architecture的值选择:armv7 armv7s arm64(选arm64时需要最低支持5.1.1,这块不太明白)

1,如果想自己的app在各个机器都能够最高效率的运行,则需要将Build Active Architecture Only改为NO,Valid architectures选择对应的指令集:armv7 armv7s arm64。这个会为各个指令集编译对应的代码,因此最后的 ipa体积基本翻了3倍。(如果不在乎app大小的话,应该这样做)

2,如果想让app体积保持最小,则现阶段应该选择Valid architectures为armv7,这样Build Active Architecture Only选YES或NO就无所谓了。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics