脚本
#!/bin/sh
#获取执行权限
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
#要build的target名
TARGET_NAME_Base=${PROJECT_NAME}
if [[ $1 ]]
then
TARGET_NAME_Base=$1
fi
#Release
CONFIGURATION="Release"
#把打包好的静态库放到桌面
UNIVERSAL_OUTPUT_FOLDER="$HOME/Desktop/${CONFIGURATION}/"
#创建输出目录,并删除之前的framework文件
mkdir -p "${UNIVERSAL_OUTPUT_FOLDER}"
rm -rf "${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME_Base}.framework"
#分别编译模拟器和真机的Framework TARGET_NAME
xcodebuild -target "${TARGET_NAME_Base}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${TARGET_NAME_Base}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
#拷贝framework到Debug目录
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${TARGET_NAME_Base}.framework" "${UNIVERSAL_OUTPUT_FOLDER}"
###合并framework,输出最终的framework到Debug目录
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${TARGET_NAME_Base}.framework/${TARGET_NAME_Base}" "${UNIVERSAL_OUTPUT_FOLDER}${TARGET_NAME_Base}.framework/${TARGET_NAME_Base}" -output "${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME_Base}.framework/${TARGET_NAME_Base}"
#删除编译之后生成的无关的配置文件
dir_path="${UNIVERSAL_OUTPUT_FOLDER}/${TARGET_NAME_Base}.framework/"
for file in ls $dir_path
do
if [[ ${file} =~ ".xcconfig" ]]
then
rm -f "${dir_path}/${file}"
fi
done
if [ -d "${SRCROOT}/build" ]
then
rm -rf "${SRCROOT}/build"
fi
rm -rf "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator" "${BUILD_DIR}/${CONFIGURATION}-iphoneos"
open "${UNIVERSAL_OUTPUT_FOLDER}"
调用:其中TestSDK
为静态库的包名
./${PROJECT_NAME}/shell.sh TestSDK
网友评论