1. 程式人生 > >iOS開發系列-Shell腳本編譯SDK

iOS開發系列-Shell腳本編譯SDK

pack export hone tput zip %d 頭文件 輸出 target

靜態庫Shell腳本

#!/bin/bash

#要build的target名
target_Name="HTKit"

#編譯模式  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

iOS開發系列-Shell腳本編譯SDK