如何使用Shell脚本编译生成Archive文件并导出签名IPA文件

 我来答
蒙MengNum1
2016-04-15 · TA获得超过2494个赞
知道大有可为答主
回答量:3004
采纳率:87%
帮助的人:843万
展开全部
使用Shell脚本编译生成Archive文件并导出签名IPA文件。
1. build 脚本说明
本Shell脚本用于build,XCode的workspace源代码工程,并导出成可重签名的IPA文件,用于分发测试安装文件和用于提交appstore审核的文件。实现辅助产品开发,测试的配置管理工作。
使用本脚本需要以下环境
- Mac OS 10.9+
- XCode 6.0 or later and command line tools
- 用于WorkSpace工程,例如使用了Cocoapods依赖库管理的工程
- *配置好开发证书和ad ho 证书(for Debug)和(for Release)
- 源代码工程中配置好Scheme名字和build
- 对Debug配置和Release配置设置好证书名称
- 确认在Xcode UI界面中能够完全build,并通过环境生成Archive和IPA,并正确签名。
- 在workspace文件夹下建立build文件夹
2. 复制脚本文件到WorkSpace目录
3. 打开终端工具,并进入workspace目录
4. 给脚本执行权限
chmod 777 ./build_one_target.sh
5. 修改脚本参数,源代码里已经有注释
需要修改的
workspace name
provisioningProfile
scheme name
build_config
代码块
代码块语法遵循标准markdown代码
#!/bin/bash

# init build configuration
# archive and ipa output path
build_path="./build"

# workspace name
build_workspace="workspacename.xcworkspace"

# project name and path
project_path=$(pwd)
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')

# provisiong profile name
provisioningProfile='"XC Ad Hoc: com.xxxxxx.yyyyyy"'

# timestamp for ouput file name
timeStamp="$(date +"%Y%m%d_%H%M%S")"

echo "$project_path/$build_workspace"
if [ ! -d "$project_path/$build_workspace" ]; then
echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option."
exit 2
fi

# get the info.plist

app_infoplist_path=${project_path}/${project_name}/${project_name}-AppStore-Info.plist
echo ${app_infoplist_path}

# get the main version
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${app_infoplist_path}")

# get the build version
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${app_infoplist_path}")

# get the svn revision
svn_revision=$(svn info |grep Revision: |awk '{print $2}')

#`svnversion -c |sed 's/^.*://' |sed 's/[A-Z]*$//'`
#svn info |grep Revision: |awk '{print $2}'

#workspace_name='*.xcworkspace'
#ls $project_path/$build_workspace &>/dev/null
#rtnValue=$?
#if [ !$rtnValue = 0 ];then
# #build_workspace=$(echo $(basename $project_path/$workspace_name))
# echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option."
# exit 2
#fi

# scheme name
build_scheme="schemename"

# buidl config. the default is Debug|Release
build_config="Release"

# clean build
clean_cmd='xcodebuild'
clean_cmd=${clean_cmd}' clean -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config}
$clean_cmd > $build_path/clean_qa.txt || exit

# build & archive, generate the archive file
archive_name="targetname_QA_${timeStamp}.xcarchive"
archive_path="./build/"$archive_name

build_cmd='xcodebuild'
build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -destination generic/platform=iOS archive -configuration '${build_config}' ONLY_ACTIVE_ARCH=NO -archivePath '${archive_path}
echo "** Archiving QA ** to the ${archive_path}"
echo ${build_cmd}
$build_cmd > ./build/build_archive_qa.log || exit

if [ ! -d "${archive_path}" ]; then
echo "** Error! ARCHIVE QA FAILED ** Please check ./build/build_archive_qa.log."
exit 2
else
echo "** ARCHIVE QA SUCCEEDED ** to the ${archive_path}"
fi

# export to ipa with QA server
ipa_name="targetname_QA_adhoc_v${bundleShortVersion}_b${bundleVersion}_rev${svn_revision}_t${timeStamp}.ipa"
ipa_path="./build/"$ipa_name

ipa_cmd='xcodebuild'
ipa_cmd=${ipa_cmd}' -exportArchive -exportFormat ipa -archivePath '${archive_path}' -exportPath '${ipa_path}' -exportProvisioningProfile '${provisioningProfile}

echo "** Exporting QA ** to the ${ipa_path}"
echo ${ipa_cmd}
eval ${ipa_cmd} > ./build/export_ipa_qa.log || exit

if [ ! -f "${ipa_path}" ]; then
echo "** Error! Export IPA QA FAILED ** Please check ./build/export_ipa_qa.log."
exit 2
else
echo "** Export IPA QA SUCCEEDED ** to the ${ipa_path}"
fi
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100

6. 执行脚本
./build_one_target.sh
大一些的工程,大约3-5分钟完成。
完成之后,在workspace目录下的build目录下,会有如下两个主要文件。
targetname_QA_20150420_094731.xcarchive
targetname_QA_adhoc_v2.1.1_b44_rev7849_t20150420_094731.ipa
xcarchive文件很重要,可以用于不同证书签名的ipa文件
ipa文件使用的是adhoc 证书导出,用于真机测试分发。证书名称在源代码中配置。根据不同的产品bundle id,做相应修改,这里的名称和证书,不具有任何商业意义。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式