前言:可能做SDK的iOS开发者都体验过打包动态库或者静态库的时候那些繁琐的步骤,需要分别选择真机和模拟器来编译,最后还要用命令行将他们合并起来,每次都这样打包的话特别麻烦。但是我们可以使用Aggregate的脚本来自动打包。
步骤1
新建一个target,选择cross-platform的Aggregate,如下图
1.png
步骤2
创建完Aggregate之后,增加一个run script,具体步骤为,选中刚刚创建的Aggregate target,然后在build phases 下面点击加号,选择 new run script phase
2.png
步骤3
在图中红色框框标注的地方输入以下脚本
3.png
如果要生成.a后缀的静态库,那么使用以下脚本
set -e
# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME="MyFramework"
FMK_NAME="IDMPCMCC"
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
# 获取当前时间
DATE=$(date +%Y%m%d-%H:%M:%S)
# 定义IDMPCMCC+当前时间 命名的文件夹名字
INSTALL_DIR=${HOME}/Desktop/IDMPCMCC${DATE}
# 支持真机静态库所在的路径
DEVICE_DIR=${BUILD_DIR}/Release-iphoneos/
# 支持模拟器静态库所在的路径
SIMULATOR_DIR=${BUILD_DIR}/Release-iphonesimulator/
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
# 配置生成静态库一些参数
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
# 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}/lib${FMK_NAME}.a" "${SIMULATOR_DIR}/lib${FMK_NAME}.a" -output "${INSTALL_DIR}/lib${FMK_NAME}.a"
open "${INSTALL_DIR}"
如果要生成.framework的静态库或者动态库的话,使用以下脚本
set -e
# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME="MyFramework"
FMK_NAME="IDMPCMCC"
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
# 获取当前时间
DATE=$(date +%Y%m%d-%H:%M:%S)
# 定义IDMPCMCC+当前时间 命名的文件夹名字
INSTALL_DIR=${HOME}/Desktop/IDMPCMCC${DATE}/${FMK_NAME}.framework
DEVICE_DIR=${BUILD_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${BUILD_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
# 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}"
open "${INSTALL_DIR}"
步骤4
选择创建的Aggregate运行即可。
4.png
网友评论