一.shell脚本合并
在Build Phases
中添加Run Script
:
# Type a script or drag a script file from your workspace to insert its path.
if [ "${ACTION}" = "build" ]
then
INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.framework
echo "输出目录"+${INSTALL_DIR}
DEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework
echo "真机目录"+${DEVICE_DIR}
SIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework
echo "模拟器目录"+${SIMULATOR_DIR}
# 如果真机包或模拟包不存在,则退出合并
if [ ! -d "${DEVICE_DIR}" ] || [ ! -d "${SIMULATOR_DIR}" ]
then
echo "真机包或模拟包不存在,exit"
exit 0
fi
# 如果合并包已经存在,则替换
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# 使用lipo命令将其合并成一个通用framework
# 最后将生成的通用framework放置在工程根目录下新建的Products目录下
lipo -create "${DEVICE_DIR}/${PROJECT_NAME}" "${SIMULATOR_DIR}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}"
#合并完成后打开目录
open "${SRCROOT}/Products"
fi
注1:frameworks的包名一定要和工程名一样
注2:可command
+9
,点击右侧Build查看shell的运行结果:
image.png
二.手动合并
1.合并
lipo -create xxxx/ProjectName.framework/ProjcetName xxxx/ProjectName.framework/ProjcetName -output xxxx/ProjectName.framework/ProjectName
合并的只是二进制文件,合并后将二进制文件替换掉ProjectName.framework中的二进制。
2.检验:
lipo -info xxx/ProjectName.framework/ProjcetName
结果是:
xxxxxxx are: x86_64 armv7 arm64
网友评论