-
制作靜態(tài)庫(kù)
創(chuàng)建靜態(tài)庫(kù) frameWork 默認(rèn)是動(dòng)態(tài)庫(kù)
BuildSetting —> 搜索 “Mach” 更改為Static Library
- 查看支持架構(gòu):lipo -info 靜態(tài)庫(kù)名稱
制作靜態(tài)庫(kù)一般在release 環(huán)境下工作生成的庫(kù)可以支持所有架構(gòu)
4s—>5 :i386
5s—>6plus : x86_64
真機(jī):
3gs —> 4s : armv7 (靜態(tài)庫(kù)只要支持armv7,就可以支持armv7s
5 – > 5c : armv7s
5s —>X :arm64
- 靜態(tài)庫(kù)合并、分離:
- 合并:$: lipo -create 庫(kù)1 庫(kù)2 -output 新的路徑
- 分離:$:lipo [通用庫(kù)] -thin [armv7/arm64] -output [輸出路徑]
- 靜態(tài)庫(kù) 瘦身 reduce lib size
* make sure that you set Generate Debug Symbols to NO in your build settings. This can reduce the size of your static library by about 30%.
點(diǎn)擊 target -> build settings -> Generate Debug Symbols ->設(shè)置為NO
* In your target's build settings look for 'Optimization Level'. By switching that to 'Fastest, Smallest -Os' you'll permit the compiler to sacrifice some speed for size.
擊 target -> build settings -> Optimization Level ->設(shè)置為Fastest, Smallest -Os
- 靜態(tài)庫(kù)分類方法找不到問(wèn)題
官網(wǎng)解釋:https://developer.apple.com/library/content/qa/qa1490/_index.html
Technical Q&A QA1490 :
"An impedance mismatch between UNIX static libraries and the dynamic nature
of Objective-C can cause category methods in static libraries to not be linked
into an app, resulting in "selector not recognized" exceptions when the methods
aren't found at runtime."
這段話的意思就是:鏈接器在處理包含Category方法的UNIX的靜態(tài)庫(kù)時(shí),沒(méi)有將
Category的方法鏈接到APP中,造成這個(gè)錯(cuò)誤。具體的細(xì)節(jié)在本文的補(bǔ)充部分展開(kāi)。
可以看出,解決這個(gè)錯(cuò)誤的方法就是:將Category的方法鏈接到APP中,這樣
APP運(yùn)行時(shí),就能夠找到對(duì)應(yīng)的selector。而 –ObjC就可以完成這個(gè)任務(wù)。"-
ObjC"的作用是:將靜態(tài)庫(kù)中任何Objective-C代碼都鏈接到APP中。任何
Objective-C代碼當(dāng)然也包括Category的方法??梢钥闯觯褂?ObjC可能會(huì)鏈接
很多靜態(tài)庫(kù)中未被使用的Objective-C代碼,極大的增加APP的代碼體積。
"-ObjC" 的兄弟
| Flags | 位置 | 作用 |
|---|---|---|
| -Objc | Other Linker Flags | 鏈接靜態(tài)庫(kù)中所有的Objective-C代碼 |
| -all_load | Other Linker Flags | 鏈接靜態(tài)庫(kù)中所有的代碼 |
| -force_load | Other Linker Flags | 鏈接指定靜態(tài)庫(kù)中所有的代碼 |
