美文网首页
iOS Aggregate生成.framework

iOS Aggregate生成.framework

作者: IT小妞儿 | 来源:发表于2021-06-28 11:33 被阅读0次

创建Aggregate

选中TARGETS的工程 —> 点击Editor —> 选择Add Target —> 创建Aggregate —> 点击Next创建

image

嵌入脚本

选择刚刚创建的Aggregate —> 选中Build Phases —> 点击左侧+ —> 选择 New Run Script Phase

image

复制脚本到刚刚新建的New Run Script Phase

# Sets the target folders and the finalframework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME="FraSDK"
# Install dir will be the final output tothe framework.
# The following line create it in the rootfolder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after theframework creation.  
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator build
# 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 binaryfiles (i386 + armv6/armv7) into one Universal final product. 
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products"

复制完成如下图所示

image

编译

选择刚刚创建的Aggreate —> 设备选择Generic iOS Device(iOS通用设备) —> command + B 编译

image

编译成功,会自动跳出一个finder,即生成的.framework,支持真机和模拟器

image

问题集锦

1. 不支持i386和x86_64

问题描述:执行上述命令在部分项目会出现如下问题

image

解决方案:

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
改为
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO VALID_ARCHS="i386 x86_64" clean build

常用命令行

查看静态库支持的系统

cd 静态库文件夹
lipo -info 静态库名

相关文章

网友评论

      本文标题:iOS Aggregate生成.framework

      本文链接:https://www.haomeiwen.com/subject/wbnbfhtx.html