参考:https://www.jianshu.com/p/c796fcba1604
步骤:
1.创建一个集合target。
2.给集合添加依赖库(这一步可以省略因为是用脚本编译出了工程的模拟器和真机库文件,后面的脚本已经把两个库合并。)
3.添加脚本。
shell脚本:
framework:
#创建输出目录,并删除之前的framework文件mkdir -p"${UNIVERSAL_OUTPUT_FOLDER}"rm -rf"${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework"#分别编译模拟器和真机的Frameworkxcodebuild -target"${TARGET_NAME}"ONLY_ACTIVE_ARCH=NO -configuration${CONFIGURATION}-sdk iphoneos BUILD_DIR="${BUILD_DIR}"BUILD_ROOT="${BUILD_ROOT}"clean buildxcodebuild -target"${TARGET_NAME}"ONLY_ACTIVE_ARCH=NO -configuration${CONFIGURATION}-sdk iphonesimulator BUILD_DIR="${BUILD_DIR}"BUILD_ROOT="${BUILD_ROOT}"clean build#拷贝framework到univer目录cp -R"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework""${UNIVERSAL_OUTPUT_FOLDER}"#合并framework,输出最终的framework到build目录lipo -create -output"${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework/${TARGET_NAME}""${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME}.framework/${TARGET_NAME}""${BUILD_DIR}/${CONFIGURATION}-iphoneos/${TARGET_NAME}.framework/${TARGET_NAME}"#删除编译之后生成的无关的配置文件dir_path="${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME}.framework/"forfileinls$dir_pathdoif[[${file}=~".xcconfig"]]thenrm -f"${dir_path}/${file}"fidone#判断build文件夹是否存在,存在则删除if[ -d"${SRCROOT}/build"]thenrm -rf"${SRCROOT}/build"firm -rf"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator""${BUILD_DIR}/${CONFIGURATION}-iphoneos"#打开合并后的文件夹open"${UNIVERSAL_OUTPUT_FOLDER}"
静态库:
#!/bin/sh#要build的target名target_Name=${PROJECT_NAME}if[[$1]]thentarget_Name=$1fiUNIVERSAL_OUTPUT_FOLDER="${SRCROOT}/${PROJECT_NAME}_Products"# 创建输出目录,并删除之前的文件rm -rf"${UNIVERSAL_OUTPUT_FOLDER}"mkdir -p"${UNIVERSAL_OUTPUT_FOLDER}"# 分别编译真机和模拟器版本xcodebuild -target"${target_Name}"ONLY_ACTIVE_ARCH=NO -configuration${CONFIGURATION}-sdk iphoneos BUILD_DIR="${BUILD_DIR}"BUILD_ROOT="${BUILD_ROOT}"clean buildxcodebuild -target"${target_Name}"ONLY_ACTIVE_ARCH=NO -configuration${CONFIGURATION}-sdk iphonesimulator BUILD_DIR="${BUILD_DIR}"BUILD_ROOT="${BUILD_ROOT}"clean build#复制头文件到目标文件夹HEADER_FOLDER="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/include/${target_Name}"if[[ -d"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/usr/local/include"]]thenHEADER_FOLDER="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/usr/local/include"ficp -R"${HEADER_FOLDER}""${UNIVERSAL_OUTPUT_FOLDER}"#合成模拟器和真机.a包lipo -create"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${target_Name}.a""${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${target_Name}.a"-output"${UNIVERSAL_OUTPUT_FOLDER}/lib${target_Name}.a"# 判断build文件夹是否存在,存在则删除if[ -d"${SRCROOT}/build"]thenrm -rf"${SRCROOT}/build"fi#打开目标文件夹open"${UNIVERSAL_OUTPUT_FOLDER}"