每次更新sdk都需要重复的在真机下build,在模拟器下build,然后再合并静态库;为了解放双手,尝试着写了个脚本,一步完成以上工作。
一、脚本文件
#!/bin/bash
#要build的target名
target_Name=XXX
#编译模式 Release、Debug
build_model=Release
#获取工程当前所在路径
project_path=$(pwd)
#编译文件路径
buildPath=${project_path}/build
#导出sdk地址
exportSdkPath=~/Desktop/${target_Name}-SDK/${build_model}
if [ ! -d $exportSdkPath ]; then
mkdir -p $exportSdkPath;
fi
#真机sdk路径
iphoneos_path=${buildPath}/${build_model}-iphoneos/lib${target_Name}.a
#模拟器sdk路径
simulator_path=${buildPath}/${build_model}-iphonesimulator/lib${target_Name}.a
#合并后sdk路径
merge_path=${exportSdkPath}/lib${target_Name}.a
#build之前clean一下
xcodebuild -target ${target_Name} clean
#模拟器build
xcodebuild -target ${target_Name} -configuration ${build_model} -sdk iphonesimulator
#真机build
xcodebuild -target ${target_Name} -configuration ${build_model} -sdk iphoneos
#复制头文件到目标文件夹
cp -R ${buildPath}/${build_model}-iphoneos/include/${target_Name} ${exportSdkPath}
#合并模拟器和真机.a包
lipo -create ${iphoneos_path} ${simulator_path} -output ${merge_path}
#压缩合并后的文件
#压缩后的文件名
package_date=`date '+%Y-%m-%d日%X'`
sdk_zip_name=lib${target_Name}_${build_model}_${package_date}.zip
#跳转到sdk的输出路径
cd ${exportSdkPath}
#压缩sdk输出路径下的所有文件
zip -r ~/Desktop/${target_Name}-SDK/${sdk_zip_name} ./*
#打开合并后的sdk所在路径
open ${exportSdkPath}
#删除build文件
if [ -d ${buildPath} ]; then
rm -rf ${buildPath}
fi
二、使用方法
1.打开终端使用vi、vim命令创建脚本文件 xxx.sh
2.复制以上脚本内容到 xxx.sh
3.将 xxx.sh文件导入sdk工程根目录下
4.修改对应的工程名target_Name,及编译方式build_model
5.打开终端 cd到sdk工程根目录下
6.终端执行 sh xxx.sh