【IOS自动化解放双手系列二】命令行打IPA包和上传蒲公英

这是解放双手的第二部分,mac端通过shell脚本自动打包上传IPA包
导出工程部分可以参考上篇文章。

【IOS自动化解放双手系列一】unity3D导出xcode 工程并配置各种权限

shell代码如下

#! bin/bash



###############使用方法
#1、关闭unity客户端
#2、命令行进入目录直接执行:sh IosBulid.sh
#3、静静的等待上传蒲公英完成即可
clear
echo ""
echo "**************** 自动开始打IOS包  ****************  "
ROOT=$( cd "$( dirname "$0"  )" && cd .. && pwd  )

#UNITY程序的路径#
UNITY_PATH=/Applications/Unity/Unity.app/Contents/MacOS/Unity
#游戏程序路径#
PROJECT_PATH=${ROOT}Assets/Scripts/Framework/Editor
#ToolsMenu.ExportIOSProject 是unity中的静态方法
#在Unity中到处 Android工程#
$UNITY_PATH -projectPath $PROJECT_PATH -executeMethod ToolsMenu.ExportIOSProject project-$1 -quit

echo "**************** 导出工程完毕  ****************  "
export LC_ALL=zh_CN.GB2312;
export LANG=zh_CN.GB2312

###############设置

buildConfig="Release" #编译的方式, 如Release,Debug等
if [ "$1" = "highbeta" ] ; then
    buildConfig="ReleaseHighTest"
elif [ "$1" = "beta" ] ; then
    buildConfig="ReleaseTest"
elif [ "$1" = "high" ] ; then
    buildConfig="ReleaseHigh"
else
    echo "Release"
fi
echo "$1:Congfig:${buildConfig}"

projectName=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'` #项目名称

###############编译目录
buildRootDir=~/Desktop/$projectName-IPA #ipa,icon最后所在的目录绝对路径
if [ -d "$buildRootDir" ]; then
echo $buildRootDir
else
echo "文件目录不存在"
mkdir -pv $buildRootDir
echo "创建${buildRootDir}目录成功"
fi


currentDir=`pwd`
#xcoed 工程目录
projectDir="$currentDir/Project/DeviceSDK"
cd $buildRootDir
rm -rf ./build
mkdir build
buildProgressDir=$buildRootDir/build #打包过程目录
#cd $buildProgressDir
#git clone ${gitPath}

#projectDir=$buildProgressDir/$projectName/$projectName #项目所在目录的绝对路径
echo $projectDir
exportPlist=$currentDir/build.plist  #build.plist路径
archivePath=$buildProgressDir/${projectName}.xcarchive #xcarchive路径

###############获取版本号,bundleID
infoPlist="$projectDir/Info.plist"
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $infoPlist`
bundleIdentifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $infoPlist`
bundleBuildVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $infoPlist`

###############开始编译app
echo $projectDir
cd $projectDir
xcodebuild -target ${projectName} -configuration ${buildConfig} -sdk iphoneos clean  SYMROOT=$buildProgressDir
xcodebuild archive  -project $projectName.xcodeproj -scheme $projectName -archivePath ${archivePath} -configuration ${buildConfig}

#判断编译结果
if test $? -eq 0
then
echo "~~~~~~~~~~~~~~~~~~~编译成功~~~~~~~~~~~~~~~~~~~"
else
echo "~~~~~~~~~~~~~~~~~~~编译失败~~~~~~~~~~~~~~~~~~~"
exit 1
fi

###############开始打包成.ipa
appDir=$buildProgressDir/$findFolderName  #app所在路径
echo "开始打包${archivePath}$buildProgressDir....."
xcodebuild -exportArchive -archivePath $archivePath -exportPath $buildProgressDir -exportOptionsPlist $exportPlist -configuration ${buildConfig}


###############检查文件是否存在确认打包成功
exportIpaPath=$buildProgressDir/$projectName.ipa
if [ -f "$exportIpaPath" ]
then
echo "$exportIpaPath 生成成功."
else
echo "打包失败."
exit 1
fi

###############复制文件到主目录
finalIPAPath=${buildRootDir}/${projectName}-$(date +%Y%m%d_%H%M).ipa
cp -f -p $exportIpaPath  $finalIPAPath   #拷贝ipa文件
echo "复制$ipaName.ipa到${finalIPAPath}成功"
echo "~~~~~~~~~~~~~~~~~~~结束编译,处理成功~~~~~~~~~~~~~~~~~~~"
#open $buildRootDir

# ###############上传到蒲公英
export LANG=en_US
export LC_ALL=en_US;
echo "正在上传到蒲公英...."
curl -F "file=@$finalIPAPath" -F "uKey=XXX" -F "_api_key=XXX" http://www.pgyer.com/apiv1/app/upload -F "updateDescription=QA $(date +%Y%m%d_%H%M).ipa $bundleVersion"
#判断上传结果
if test $? -eq 0
then
echo "~~~~~~~\^o^/~~~~上传到蒲公英成功~~~~\^o^/~~~"
else
echo "~~~~~\(╯-╰)/~~~~~~~上传到蒲公英失败~~~~~\(╯-╰)/~~~~~"
exit 1
fi
cd $currentDir
sh bugly.sh "1.1.2"
cd $buildRootDir
###############删除构建目录
rm -rf $buildProgressDir

至此命令行打包结束
接下来我们写上传bugly

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值