iOS~靜態庫開發

 

在工做中,咱們經常須要製做本身的靜態庫,封裝一些模塊,以便共享使用。html

 

多架構(Multi-Architecture)編譯

iOS app須要在許多不一樣的CPU架構下運行:ios

  • arm7: 在最老的支持iOS7的設備上使用架構

  • arm7s: 在iPhone5和5C上使用app

  • arm64: 運行於iPhone5S的64位 ARM 處理器 上框架

  • i386: 32位模擬器上使用iphone

  • x86_64: 64爲模擬器上使用ui

 

靜態庫有真機和模擬器之分,通常能夠生產通用靜態庫.net

 

http://www.cocoachina.com/ios/20150226/11182.htmlcode

http://www.cocoachina.com/ios/20141126/10322.htmlhtm

http://www.cocoachina.com/ios/20150127/11022.html

http://blog.csdn.net/pjk1129/article/details/7255163

 

使用Xcode7.0.1 編譯出的靜態庫

真機支持armv7 arm64 默認竟然不帶armv7s

模擬器支持x86_64

bogon:~ shenlong$ lipo -info /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphoneos/libstatic_test.a
Architectures in the fat file: /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphoneos/libstatic_test.a are: armv7 arm64
bogon:~ shenlong$ lipo -info /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphonesimulator/libstatic_test.a
input file /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphonesimulator/libstatic_test.a is not a fat file
Non-fat file: /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphonesimulator/libstatic_test.a is architecture: x86_64

合併2個靜態庫

bogon:~ shenlong$ lipo -info /Users/shenlong/Desktop/libMyStatic.a
Architectures in the fat file: /Users/shenlong/Desktop/libMyStatic.a are: armv7 x86_64 arm64

目前只支持 armv7  arm64 x86_64 不支持armv7s(iPhone5 iPhone5C)

下圖在CPU框架中添加支持armv7s

 

25.png

 

如上圖,框架中添加armv7s後

bogon:~ shenlong$ lipo -info /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphoneos/libstatic_test.a
Architectures in the fat file: /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphoneos/libstatic_test.a are: armv7 arm64 armv7s

再次合併

lipo -create /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphoneos/libstatic_test.a /Users/shenlong/Library/Developer/Xcode/DerivedData/static_test-dsdhaafkwbcsczelhkvovfhbaijl/Build/Products/Debug-iphonesimulator/libstatic_test.a -output /Users/shenlong/Desktop/libMyStatic.a

查看支持框架

bogon:~ shenlong$ lipo -info /Users/shenlong/Desktop/libMyStatic.a
Architectures in the fat file: /Users/shenlong/Desktop/libMyStatic.a are: armv7 armv7s x86_64 arm64

這樣就徹底支持armv7 armv7s arm64 全部的CPU框架了。

 

就是這樣!

相關文章
相關標籤/搜索