利用xcodebuild自动打包SDK并生成xcframework包

注意此脚本只适用于.framework格式的静态库

创建脚本文件
cd 你的项目的根目录
touch autoBuild.sh
编辑脚本文件
FRAMEWORK_NAME='YLUISDK'

WORK_DIR='build'

#release环境下,generic ios device编译出的framework。这个framework只能供真机运行。
DEVICE_DIR=${WORK_DIR}/'UninstalledProducts'/'iphoneos'/${FRAMEWORK_NAME}'.framework'

#release环境下,simulator编译出的framework。这个framework只能供模拟器运行。
SIMULATOR_DIR=${WORK_DIR}/'UninstalledProducts'/'iphonesimulator'/${FRAMEWORK_NAME}'.framework'

#framework的输出目录
OUTPUT_DIR=./'AProducts'

// ios release
xcodebuild archive \
-target ${FRAMEWORK_NAME} \
-destination="iOS" -sdk iphoneos \
-configuration Release\
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES\

#// ios simulator release
xcodebuild archive \
-target ${FRAMEWORK_NAME} \
-destination="iOS Simulator"  -sdk iphonesimulator \
-configuration Release\
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

#如果输出目录存在,即移除该目录,再创建该目录。目的是为了清空输出目录。
if [ -d ${OUTPUT_DIR}/${FRAMEWORK_NAME}.xcframework ]; then
rm -rf ${OUTPUT_DIR}/${FRAMEWORK_NAME}.xcframework
fi

#将打包好的framwork合并成xcframework
xcodebuild -create-xcframework \
-framework ${DEVICE_DIR} \
-framework ${SIMULATOR_DIR} \
-output ${OUTPUT_DIR}/${FRAMEWORK_NAME}.xcframework

#删除临时目录
rm -r ${WORK_DIR}
#打开输出目录
open ${OUTPUT_DIR}

只需将FRAMEWORK_NAME的值改成你的项目的名字,然后保存关闭在当前路径执行
./autoBuild.sh
执行完成后你的项目的根目录下就会生成一个"AProducts"文件夹,里面就是打包好的xcframework。

你可能感兴趣的:(利用xcodebuild自动打包SDK并生成xcframework包)