iOS Framework自动打包

同事写的更好,在此奉上;

参考链接: https://github.com/guojunliu/steve-document/blob/master/SDK%E8%87%AA%E5%8A%A8%E6%89%93%E5%8C%85.md

背景:

由于iOS Framework打包出来是分CPU指令集的,所以需要每个CPU指令集都打包一个Framework,然后使用lipo -create命令将所有CPU指令集合并,才能形成一个兼容所有设备和模拟器的Framework。这样的打包流程复杂而繁琐,对于需要经常打包测试的需求来说明显是不合适的。

解决方案

使用xcode Aggregate工具中的Run Script自动进行不同CPU指令集打包,并自动合并所有CPU指令集

处理器指令集介绍

  • ARM处理器
    • armv7
    • armv7s
    • arm64
  • Mac处理器
    • i386
    • x86_64
指令集设备支持设备
arm64真机64位iPhone6s、iphone6s plus、iPhone6、iPhone6 plus、iPhone5S、iPad Air、 iPad mini2
armv7s真机32位iPhone5、iPhone5C、iPad4(iPad with Retina Display)
armv7真机32位iPhone4、iPhone4S、iPad、iPad2、iPad3(The New iPad)、iPad mini、iPod Touch 3G、iPod Touch4
i386模拟器32位针对intel通用微处理器32位处理器
x86_64模拟器64位针对x86架构的64位处理器

添加 Aggregate

  • 使用Xcode打开打包工程
  • FileNewTargetCross-platformAggregate
  • 命名为AvidlyAdsSDKArchive(自由命名)

添加 Run Script

  • 打开AvidlyAdsSDKArchive``Aggregate
  • BuildPhasesNew+Cross-platformNew Run Script Phase
  • 打开新建的Run Script,在shell中键入打包代码

shell编写打包代码

# 工程名称
# 如果工程名称和Framework的Target名称不一样的 话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}

# 工程Info.list路径
InfoPlist=${SRCROOT}/${PROJECT_NAME}/Info.plist

# 工程Version
Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $InfoPlist)
Version=${Version//./}

# 工程Build
Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $InfoPlist)

# SDK文件夹名称
SDKFilePath=${SRCROOT}/${PROJECT_NAME}_${Version}_${Build}

# 文件路径是否存在
if [ -d "${SDKFilePath}" ]
then
rm -rf "${SDKFilePath}"
fi
mkdir -p "${SDKFilePath}"

# 当前时间
updataDate=`date +%F`

# 将信息写入文件
updataFileName=${SDKFilePath}/version.md
touch ${updataFileName}
echo 版本:${Version} >> ${updataFileName}
echo 编译:${Build} >> ${updataFileName}
echo 时间:${updataDate} >> ${updataFileName}
echo 更新: >> ${updataFileName}

# SDK目录
INSTALL_DIR=${SDKFilePath}/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean 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 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}"
rm -r "${WRK_DIR}"
open "${SRCROOT}"


简单版:

# Sets the target folders and the finalframework product.
# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
FMK_NAME=${PROJECT_NAME}
# SDK目录
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean 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 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}"
rm -r "${WRK_DIR}"
open "${SRCROOT}"


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值