xcodebuild 自动打包脚本
程序员文章站
2022-07-12 22:20:55
...
1.简单脚本 存放目录需要手动创建好
#!/bin/bash
home_path=$(cd `dirname $0`; pwd)
target_name="StrongSelf"
upload_path="/Users/kangxg/Desktop/appName/myProjectTest/archive/"
target_path="$home_path/StrongSelf/"
archive_path="$home_path/archive/$target_name"
ipa_path="$home_path/ipa/"
provisoning_profile="$home_path/ExportOptions.plist"
log_path="$home_path/log.txt"
workspace_name="$home_path/$target_name/$target_name.xcworkspace"
archivie_name="$home_path/archive/$target_name.xcarchive"
configuration="Debug"
scheme="devStrongSelf"
echo "根路径: $home_path"
echo "归档路径: $archive_path"
echo "归档文件名称: $archivie_name"
echo "ipa路径:$ipa_path"
echo "plist路径:$provisoning_profile"
echo "configuration配置:$configuration"
echo "target_name项目名称:$target_name"
echo "workspace_name工作空间名称:$workspace_name"
echo "scheme名称:$scheme"
xcodebuild \
clean -workspace "$workspace_name" \
-scheme "$scheme" \
-configuration "$configuration"
xcodebuild \
archive -workspace "$workspace_name" \
-scheme "$scheme" \
-configuration "$configuration" \
-archivePath "$archive_path"
xcodebuild \
-exportArchive -archivePath "$archivie_name" \
-exportPath "$ipa_path" \
-exportOptionsPlist "$provisoning_profile" >> $log_path
exit 0
2.补充的(自动创建需要访问的目录,完成后打开目录)
#使用方法
if [ ! -d ./ipa ];
then
mkdir -p ipa;
fi
if [ ! -d ./archive ];
then
mkdir -p archive;
fi
if [ ! -d ./log ];
then
mkdir -p log;
fi
#工程绝对路径
home_path=$(cd `dirname $0`; pwd)
echo "工程绝对路径:$home_path"
#工程名 将XXX替换成自己的工程名 {project_path}/
project_name="StrongSelf"
workSpacePath="$home_path/$project_name/$project_name.xcworkspace"
echo "工程名称路径:$workSpacePath"
#Users/kangxg/Desktop/appName/aixueTest/aixue
#scheme名 将XXX替换成自己的sheme名
scheme_name="devStrongSelf"
#打包模式 Debug/Release
development_mode="Debug"
#build文件夹路径
build_path="$home_path/archive/$project_name"
archivie_name="$home_path/archive/$project_name.xcarchive"
#plist文件所在路径
exportOptionsPlistPath="$home_path/ExportOptions.plist"
#导出.ipa文件所在路径
exportIpaPath="$home_path/ipa/"
log_path="$home_path/log/log.txt"
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
##
read number
while([[ $number != 1 ]] && [[ $number != 2 ]])
do
echo "Error! Should enter 1 or 2"
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
read number
done
if [ $number == 1 ];
then
development_mode=Release
exportOptionsPlistPath="$home_path/exportAppstore.plist"
## 证书名字
else
development_mode=Debug
exportOptionsPlistPath="$home_path/ExportOptions.plist"
fi
echo 'exportOptionsPlistPath= $exportOptionsPlistPath'
echo '///-----------'
echo '/// 正在清理工程'
echo '///清理路径 $workSpacePath'
echo '///-----------'
xcodebuild \
clean -workspace "$workSpacePath" \
-scheme "$scheme_name" \
-configuration "$development_mode" >> $log_path -quiet || exit
echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''
echo '///-----------'
echo "/// 正在编译工程:$development_mode"
echo '///编译路径'
echo '///-----------'
xcodebuild \
archive -workspace "$workSpacePath" \
-scheme "$scheme_name" \
-configuration "$development_mode" \
-archivePath "$build_path" >> $log_path -quiet || exit
echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''
echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
xcodebuild \
-exportArchive -archivePath "$archivie_name" \
-exportPath "$exportIpaPath" \
-exportOptionsPlist "$exportOptionsPlistPath" \
>> $log_path -quiet || exit
if [ -e $exportIpaPath/$scheme_name.ipa ];
then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成 '
echo '///-----------='
echo ''
echo "已运行完毕"
exit 0
3.打包前目录结构
4.打包后目录
5.plist 文件
参考文章: http://blog.csdn.net/lovechris00/article/details/79141752