- 定义一系列变量
1
2
3
4
5
6
7
8ProjectRootDir="$(PWD)"
ProjectName="XingHomecloud"
Configuration="Release"
IPAPath="$ProjectRootDir/ipa"
IPATitle="XingHC"
TargetBuildDir="$ProjectRootDir/build"
CODE_SIGN_STRING="iPhone Distribution: ZTE CORPORATION"
PROVISIONING_PROFILE_STRING="$IPAPath/ZXIPTV_InHouse.mobileprovision"
- 根据参数确定
ipa
包的名字以及Configuration
的值1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20IPAName="$IPATitle.ipa"
VersionName=""
for arg in "$@"; do
echo $arg
done
if [ x$1 != x ]; then
echo "参数1, VersionName = $1"
VersionName=$1
IPAName="$IPATitle-$VersionName.ipa"
fi
if [ x$2 != x ]; then
echo "参数2, Configuration = $2"
Configuration=$2
fi
echo "IPAName = $IPAName"
echo "Configuration = $Configuration"
- 清理项目和临时文件目录
1
2rm -rf $TargetBuildDir
/usr/bin/xcodebuild clean -configuration $Configuration
如果是单个project
1
2
3/usr/bin/xcodebuild -target $ProjectName \
-configuration $Configuration \
CODE_SIGN_IDENTITY="$CODE_SIGN_STRING"如果是工作空间
1
2
3
4
5
6
7/usr/bin/xcodebuild -workspace $ProjectRootDir/$ProjectName.xcworkspace \
-scheme $ProjectName \
-configuration $Configuration \
-sdk iphoneos \
CODE_SIGN_RESOURCE_RULES_PATH='$(SDKROOT)/ResourceRules.plist' \
OBJROOT=$TargetBuildDir \
TARGET_BUILD_DIR=$TargetBuildDir \这里因为设置了
TARGET_BUILD_DIR
,所以需要在工程的Library Search Path
中添加设置的目录,否则编译会报错,信息是找不到引用的第三方库:library not found for -l AFNetworking
,但是直接在Xcode中编译会出现一个找不到目录的警告,这个暂时还没有办法两全其美的办法。
另外,如果在项目中有额外的静态库,还需要将静态库以及头文件拷贝到TARGET_BUILD_DIR
中。1
cp $(ProjectRootDir)/$ProjectName/SDK/* $TargetBuildDir
- 打包IPA
1
2
3
4
5
6
7mkdir -p $IPAPath
/usr/bin/xcrun -sdk iphoneos \
PackageApplication \
-v $TargetBuildDir/$ProjectName.app \
-o $IPAPath/$IPAName \
--sign "$CODE_SIGN_STRING"
--embed "$PROVISIONING_PROFILE_STRING"
- 清理临时目录
1
rm -rf $TargetBuildDir