armv7、arm64、Valid Architectures是什么东西,有啥区别

iOS 中的 armv7,armv7s,arm64,i386,x86_64 都是什么
在做静态库的时候以及引用静态库的时候经常会遇到一些关于真机模拟器不通用的情况,会报错找不到相应库导致编译失败,

这里简单记录一下各种设备支持的架构。

iOS测试分为模拟器测试和真机测试,处理器分为32位处理器,和64位处理器,

模拟器32位处理器测试需要i386架构,(iphone5,iphone5s以下的模拟器)

模拟器64位处理器测试需要x86_64架构,(iphone6以上的模拟器)

真机32位处理器需要armv7,或者armv7s架构,(iphone4真机/armv7, ipnone5,iphone5s真机/armv7s)

真机64位处理器需要arm64架构。(iphone6,iphone6p以上的真机)

project -> target -> building setting -> Arhitectures 设置

debug属性设置为no的时候,会编译支持所有架构的版本,编译的速度会变慢,设置为yes 的时候,只编译当前的architecture版本,编译速度快。

一般情况下,debug 设置为yes,release为no,这样发行版本能适应不同设备。

现在先说说不同型号的iPhone都使用的是什么指令集:
ARMv8/ARM64 = iPhone 5s, iPad Air, Retina iPad Mini
ARMv7s = iPhone 5, iPhone 5c, iPad 4
ARMv7 = iPhone 3GS, iPhone 4, iPhone 4S, iPod 3G/4G/5G, iPad, iPad 2, iPad 3, iPad Mini
ARMv6 = 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中明确指出:
Changes
General: iOS

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

如何选择支持的指令集

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

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

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

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

猜你喜欢

转载自blog.csdn.net/weixin_43883776/article/details/87879134