創(chuàng)建Aggregate
選中TARGETS的工程 —> 點(diǎn)擊Editor —> 選擇Add Target —> 創(chuàng)建Aggregate —> 點(diǎn)擊Next創(chuàng)建

image
嵌入腳本
選擇剛剛創(chuàng)建的Aggregate —> 選中Build Phases —> 點(diǎn)擊左側(cè)+ —> 選擇 New Run Script Phase

image
復(fù)制腳本到剛剛新建的New Run Script Phase
# Sets the target folders and the finalframework product.
# 如果工程名稱和Framework的Target名稱不一樣的話,要自定義FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME="FraSDK"
# Install dir will be the final output tothe framework.
# The following line create it in the rootfolder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after theframework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binaryfiles (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products"
復(fù)制完成如下圖所示

image
編譯
選擇剛剛創(chuàng)建的Aggreate —> 設(shè)備選擇Generic iOS Device(iOS通用設(shè)備) —> command + B 編譯

image
編譯成功,會(huì)自動(dòng)跳出一個(gè)finder,即生成的.framework,支持真機(jī)和模擬器

image
問(wèn)題集錦
1. 不支持i386和x86_64
問(wèn)題描述:執(zhí)行上述命令在部分項(xiàng)目會(huì)出現(xiàn)如下問(wèn)題

image
解決方案:
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
改為
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO VALID_ARCHS="i386 x86_64" clean build
常用命令行
查看靜態(tài)庫(kù)支持的系統(tǒng)
cd 靜態(tài)庫(kù)文件夾
lipo -info 靜態(tài)庫(kù)名