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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM