iOS Architectures 浅谈

  iOS项目打包,或者只是在项目里面调用第三方静态库抑或是自己新建一个静态库,就要无可避免的和Architectures打交道。Architectures在Targets面板的Build Settings下,如下图红框所示:

  首先请注意上图蓝色框部分,选项里面出现了好几个ARM,ARM指的就是ARM处理器,它被普遍使用在嵌入式设备中,例如手机、平板等。不同的设备对应的处理器架构版本不同,设备只会执行对应处理器版本的指令集。举个栗子,iPhone5的处理器版本是armv7s,如果你最终只编译了arm64版本,项目是不可能跑在iPhone5上面的,再或者你调用了一个只支持arm64的第三方静态库,而你的项目需要支持armv7和armv7s,这个时候你导入这个第三方库编译就会报错。但是有一点需要注意的就是向下兼容原则,即你的项目只编译了armv7s,支持arm64的设备是能够正常运行的,只是这个时候就无法完全发挥手机的性能。稍微统计了下目前iOS设备对应的ARM处理器:

  

 Architectures 和 Valid Architectures

/*

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和Valid Architectures搞混淆。Valid Architectures表示的是你的项目所支持的处理器架构列表,是一个大的集合,而Architectures表示的是你的项目编译的时候最终生成的二进制文件包含的处理器架构集合。当然如果你的Architectures超出了Valid Architectures的范围,只能取Architectures和Valid Architectures的交集。一般来说,不需要修改Valid Architectures,你只要设置Architectures成你需要的架构版本就可以了。如果你理解了这两个概念,再回过头来看看苹果对Architectures和Valid Architectures的默认设置,Valid Architectures设置成:arm64、armv7、armv7s,但是Architectures只设置成:armv7、arm64。这就是说,项目虽然支持市面上大部分手机的处理器架构版本,但是最终只比编译了两个版本。这也可以理解,根据向下兼容原则,目前市面上大部分32位iOS设备都支持armv7,而64位设备都支持arm64, 对样做即保证了高性能手机的运行性能不受影响,同时减小了生成包的大小,一举两得。

Build Active Architecture Only 

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

这个属性主要用在Debug的时候。根据字面意思,就是说只编译你当前连接设备(活跃状态)的处理器版本。这个属性不需要修改,Xcode的默认设置就是Debug为Yes,Release 为No。Debug模式设置为Yes,编译的时候只编译成当前连接设备的处理器版本,会大大缩短编译时间。Release的时候,需要设置成No,你要适配市面上大部分手机,如果Release你还设置成Yes,就要呵呵了,你生成的安装包只能安装在你当前连接设备的编译类型的手机上。当然,这也是你Release编译所花的时间要大大超过Debug的原因。

因为水平有限,说的比较乱,希望你们能够理解,如果还有不懂的地方,或者内容有误,欢迎在留言区指正。

转载请注明出处:http://www.cnblogs.com/tbfirstone/p/5869528.html

原文地址:https://www.cnblogs.com/tbfirstone/p/5869528.html