合并模拟器和真机的静态库动态库aggregate
创建Aggregate的target
在Build Phases 添加Run Script,内容为
scriptFile=${SRCROOT}/universalA.sh
sh ${scriptFile}
universalA.sh放在工程根目录,内容为:
if [ "${ACTION}" = "build" ] then echo "合并模拟器真机库" target_Name=${PROJECT_NAME} echo "target_Name=${target_Name}" build_DIR=${SRCROOT}/build echo "build_DIR=${build_DIR}" #真机build生成的头文件的文件夹路径 DEVICE_DIR_INCLUDE=${build_DIR}/Release-iphoneos/include/${PROJECT_NAME} echo "DEVICE_DIR_INCLUDE=${DEVICE_DIR_INCLUDE}" #真机build生成的.a文件路径 DEVICE_DIR_A=${build_DIR}/Release-iphoneos/lib${PROJECT_NAME}.a echo "DEVICE_DIR_A=${DEVICE_DIR_A}" #模拟器build生成的.a文件路径 SIMULATOR_DIR_A=${build_DIR}/Release-iphonesimulator/lib${PROJECT_NAME}.a echo "SIMULATOR_DIR_A=${SIMULATOR_DIR_A}" #目标文件夹路径 INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME} echo "INSTALL_DIR=${INSTALL_DIR}" #目标头文件文件夹路径 INSTALL_DIR_Headers=${SRCROOT}/Products/${PROJECT_NAME}/Headers echo "INSTALL_DIR_Headers=${INSTALL_DIR_Headers}" #目标.a路径 INSTALL_DIR_A=${SRCROOT}/Products/${PROJECT_NAME}/lib${PROJECT_NAME}.a echo "INSTALL_DIR_A=${INSTALL_DIR_A}" #判断build文件夹是否存在,存在则删除 if [ -d "${build_DIR}" ] then rm -rf "${build_DIR}" fi #判断目标文件夹是否存在,存在则删除该文件夹 if [ -d "${INSTALL_DIR}" ] then rm -rf "${INSTALL_DIR}" fi #创建目标文件夹 mkdir -p "${INSTALL_DIR}" #build之前clean一下 xcodebuild -target ${target_Name} clean #模拟器build echo "开始编译iphonesimulator" xcodebuild -target ${target_Name} -configuration Release -sdk iphonesimulator #真机build echo "开始编译iphoneos" xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos #复制头文件到目标文件夹 echo "拷贝头文件" echo "头文件路劲:"${DEVICE_DIR_INCLUDE} cp -R ${DEVICE_DIR_INCLUDE} ${INSTALL_DIR_Headers} #合成模拟器和真机.a包 echo "开始合并.a库" lipo -create "${DEVICE_DIR_A}" "${SIMULATOR_DIR_A}" -output "${INSTALL_DIR_A}" #打开目标文件夹 open "${INSTALL_DIR}" fi
如果是framework:
内容为:
# Sets the target folders and the final framework product. # 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME # 例如: FMK_NAME = "MyFramework" FMK_NAME=${PROJECT_NAME} # Install dir will be the final output to the framework. # The following line create it in the root folder of the current project. INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework # Working dir will be deleted after the framework creation. WRK_DIR=build DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework # -configuration ${CONFIGURATION} # Clean and Building both architectures. xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean 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 binary files (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 "${INSTALL_DIR}"