無論是是整個xcode工程還是將部分代碼打包Framework 方法是一致的募逞,對于AppDelegate來講捞附,不要包含進(jìn)去即可
1.創(chuàng)建Framework的target
選擇Targets中的+ --> iOS -->Cocoa Touch Framework --> Next
對于使用了Cocoapod導(dǎo)入第三方的xcode工程來講 需要在Podfile中 做如下修改 之后 pod install
需要同時(shí)對住工程target 和Framework的target 配置pod環(huán)境
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
use_frameworks!
target 'xxx' do
react_native_path = "./ReactNative/node_modules/react-native"
pod "React", :path => react_native_path,:subspecs => [
'Core',
'RCTText',
'RCTImage',
'RCTLinkingIOS',
'RCTSettings',
'RCTVibration',
'RCTGeolocation',
'RCTActionSheet',
'RCTNetwork',
'RCTWebSocket'
]
pod "Yoga", :path => "#{react_native_path}/ReactCommon/yoga"
pod 'Masonry', '1.0.2'
pod 'FMDB', '2.6.2'
pod 'MJExtension', '3.0.13'
pod 'MJRefresh', '3.1.12'
pod 'AFNetworking', '3.1.0'
pod 'SVProgressHUD', '2.1.2'
pod 'TZImagePickerController', '1.7.8'
pod 'BeeCloud', '3.6.1'
pod 'HyphenateLite','3.3.2'
pod 'EaseUILite', :git =>'https://github.com/easemob/easeui-ios-hyphenate-cocoapods.git’,:tag => '3.3.2'
pod 'BaiduMapKit' #百度地圖SDK
pod 'EDStarRating', '1.1'
pod 'ReactiveObjC', '3.0.0' #測試使用
end
target ‘xxx_Framework’ do
react_native_path = "./ReactNative/node_modules/react-native"
pod "React", :path => react_native_path,:subspecs => [
'Core',
'RCTText',
'RCTImage',
'RCTLinkingIOS',
'RCTSettings',
'RCTVibration',
'RCTGeolocation',
'RCTActionSheet',
'RCTNetwork',
'RCTWebSocket'
]
pod "Yoga", :path => "#{react_native_path}/ReactCommon/yoga"
pod 'Masonry', '1.0.2'
pod 'FMDB', '2.6.2'
pod 'MJExtension', '3.0.13'
pod 'MJRefresh', '3.1.12'
pod 'AFNetworking', '3.1.0'
pod 'SVProgressHUD', '2.1.2'
pod 'TZImagePickerController', '1.7.8'
pod 'BeeCloud', '3.6.1'
pod 'HyphenateLite','3.3.2'
pod 'BaiduMapKit' #百度地圖SDK
pod 'EaseUILite', :git =>'https://github.com/easemob/easeui-ios-hyphenate-cocoapods.git’,:tag => '3.3.2'
pod 'EDStarRating', '1.1'
pod 'ReactiveObjC', '3.0.0' #測試使用
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
2.build Setting 設(shè)置
選擇工程文件>target第一項(xiàng)>Build Setting>搜索linking,然后幾個需要設(shè)置的選項(xiàng)都顯現(xiàn)出來玫恳,首先是Dead Code Stripping設(shè)置為NO逊移,網(wǎng)上對此項(xiàng)的解釋如下,大致意思是如果開啟此項(xiàng)就會對代碼中的”dead”薄嫡、”unreachable”的代碼過濾,不過這個開關(guān)是否關(guān)閉谈飒,似乎沒有多大影響岂座,不過為了完整還原framework中的代碼态蒂,將此項(xiàng)關(guān)閉也未曾不可杭措。
The resulting executable will not include any “dead” or unreachable code
然后將Link With Standard Libraries關(guān)閉,我想可能是為了避免重復(fù)鏈接
最后將Mach-O Type設(shè)為Static Library钾恢,framework可以是動態(tài)庫也可以是靜態(tài)庫手素,對于系統(tǒng)的framework是動態(tài)庫,而用戶制作的framework只能是靜態(tài)庫瘩蚪。
開始將下圖中的build Active Architecture only選項(xiàng)設(shè)為YES泉懦,導(dǎo)致其編譯時(shí)只生成當(dāng)前機(jī)器的框架,將其設(shè)置為NO后疹瘦,發(fā)現(xiàn)用模擬器編譯后生成的framework同時(shí)包含x86_64和i386架構(gòu)崩哩。不過這個無所謂,我們之后會使用編譯腳本言沐,腳本會將所有的架構(gòu)全包含
Header中將需要暴露的頭文件暴露出去邓嘹,Complie Sources 中需要編譯的xxxx.m源文件添加進(jìn)去
3.向外暴露引用文件
build Phases 中header只是聲明那些文件可以在外部可以被引用
在framework目錄下的.h 文件中講需要暴露出去的頭文件聲明一下
否則在引用的時(shí)候會出現(xiàn)如下 Miss submodule 'xxxxx.xxxx.h'的警告
4.編譯
編譯成功之后 xxx.framwork 即變?yōu)楹谏?show in finder 就會看到
show in finder 如下
Debug-iphoneos 為Debug模式下真機(jī)使用的
Debug-iphonesimulator 為Debug模式下模擬器使用的
Release -iphoneos 為Release模式下真機(jī)使用的
Release-iphonesimulator 為Release模式下模擬器使用的
5.framework框架
1.檢查framework支持的框架
使用 lipo -info 即可查看 framework所支持的架構(gòu)
lipo -info xxx_Framework
Architectures in the fat file: xxx_Framework are: armv7 arm64
2.合并framework
使用lipo -create xxx xxx -output xxx 即可將支持單個架構(gòu)的framework融合成一個支持多種架構(gòu)的framework
MacBook-Pro:Products $ lipo -create /Users/sqq/Library/Developer/Xcode/DerivedData/xxxx-ahamypgonskszeeayqaqqzajlxvq/Build/Products/Release-iphoneos/PTYL_Client_Framework.framework/PTYL_Client_Framework /Users/sqq/Library/Developer/Xcode/DerivedData/xxxx-ahamypgonskszeeayqaqqzajlxvq/Build/Products/Release-iphonesimulator/PTYL_Client_Framework.framework/xxxx -output xxx
MacBook-Pro:Products $ ls
Debug-iphoneos xxxx Release-iphonesimulator
Debug-iphonesimulator Release-iphoneos Release-universal
MacBook-Pro:Products $ lipo -info xxx
Architectures in the fat file: xxxx are: armv7 i386 x86_64 arm64
最后將output 生成的 文件 復(fù)制到Debug-iphoneos 或者Debug-iphonesimulator 任意一個下面的framework目錄下 即可
這個很重要
完畢
這里為手動合并框架,下一篇將介紹如何自動合并
下一篇
Xcode8 下 Framework 打包(二)自動打包腳本創(chuàng)建過程