1. 程式人生 > >xcode工程編譯錯誤:No architectures to compile for

xcode工程編譯錯誤:No architectures to compile for

bis clear 文檔 哪些 i386 提高 href nts b2c

問題

開發環境:xcode6,iPhone6模擬器

xcode工程編譯錯誤:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).

技術分享

原因

導致這個錯誤的原因主要是CPU的編譯架構引起的,Build Active Architecture Only屬性設置為了YES(只編譯當前模擬器指令集),當出現不兼容設備時就會出現錯誤。

解決

在工程Build Settings,設置Build Active Architecture Only屬性設置為NO,並且Architectures與Valid Architectures屬性分別添加ARMv7,ARMv7s,ARM64值,clear工程,重新build即可。

首先我們先了解一下各類型iOS設備的架構:

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 (一般不需要去支持)

要解決這個錯誤,應該關註以下幾個屬性設置:

1.Build Active Architecture Only屬性

設置為yes時,只編譯當前的設備(architecture)版本,提高debug是的編譯速度;

設置為no時,會編譯所有的版本(發布release時使用,以兼容各類型設備)。

註:編譯出的版本是向下兼容的,比如你設置此值為yes,用iphone4編譯出來的是armv7版本的,iphone5也可以運行,但是armv6的設備就不能運行。

2.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.

簡單來說就是工程被編譯成可支持哪些指令集類型,而支持的指令集越多,對應生成二進制包就越大,也就是ipa包會變大。

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.

有效編譯指令集,也就是Xcode編譯出來的二進制包類型最終從這些類型產生,而編譯出哪種指令集的包,將由Architectures與Valid Architectures(因此這個不能為空)的交集來確定,例如:
比如,你的Valid Architectures設置的支持arm指令集版本有:armv7/armv7s/arm64,對應的Architectures設置的支持arm指令集版本有:armv7s,這時Xcode只會生成一個armv7s指令集的二進制包。

編譯集選擇
如果你對ipa安裝包大小有要求,可以減少安裝包的指令集的數量,這樣就可以盡可能的減少包的大小。當然這樣做會使部分設備出現性能損失,當然在普通應用中這點體現幾乎感覺不到,至少不會威脅到用戶體檢(這就跟win7系統在32位和64位運行QQ一樣,你看得出麽?)。或者你也還在擔心這個問題,你可以把百度地圖等SDK下載下來,使用lipo、ar等命令查看一下它們的編譯架構。
註:不過,新版的app審核規則中,似乎已經逐漸要求app必須支持64位的設備,因此在今後的工程維護中得多關註解決兼容性問題。

參考文章:Xcode設置項之Architectures和Valid Architectures

xcode工程編譯錯誤:No architectures to compile for