altool 文档

使用xcode自带的xcodebuild 命令通过脚本进行打包

打包->导出ipa, 两行关键的脚本代码

1.Archive

xcodebuild archive
-archivePath <archivePath>
-project <projectName>
-workspace <workspaceName>
-scheme <schemeName> #从-list命令中获取
-configuration <Debug|Release>

2.Export

xcodebuild -exportArchive
-archivePath <xcarchivepath>
-exportPath <destinationpath>
-exportOptionsPlist <plistpath> #这个plist文件可以通过打一次ipa包里面去获取

3.upload

altool 是xcode自带的Application Loader 的命令行,可以完成提交到App Store

if [[ $number ==  ]]; then

    echo "///--------------------"
echo "/// 开始发布到 app store"
echo "///--------------------" altoolPath=/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool
"$altoolPath" --validate-app -f $export_ipa_path/$project_scheme.ipa\
-u <你的开发者账号> -p <你的开发者账号密码>\
--output-format xml
"$altoolPath" --upload-app -f $export_ipa_path/$project_scheme.ipa\
-u <你的开发者账号> -p <你的开发者账号密码>\
--output-format xml
else echo "///--------------------"
echo "/// 开始上传ipa包到蒲公英"
echo "///--------------------"
curl -F "file=@$export_ipa_path/$project_scheme.ipa"\
-F "uKey=<你的蒲公英uKey>"\
-F "_api_key=<你的蒲公英ApiKey>" https://qiniu-storage.pgyer.com/apiv1/app/upload
fi

参考:

xcodebuild命令介绍

iOS自动化打包 ---- 集成shell脚本

Xcodebuild自动打包总结

详解Shell脚本实现iOS自动化编译打包提交

iOS-如何实现每次打包编译号自动增加

https://github.com/monetking/AutoPacking-iOS

shell 脚本

#!/bin/sh

#  WallPaperScript.sh

#计时
SECONDS= #取当前时间字符串添加到文件结尾
now=$(date +"%Y%m%d-%H:%M") # 获取 setting.plist 文件路径
setting_path=./setting.plist # 项目名称
project_name=$(/usr/libexec/PlistBuddy -c "print project_name" ${setting_path}) # 项目路径
project_path=$(/usr/libexec/PlistBuddy -c "print project_path" ${setting_path}) # workspace/xcodeproj 路径(根据项目是否使用cocoapod,确定打包的方式)
if [ -d "./${project_name}.xcworkspace" ];then # 项目中存在workspace
workspace_path="${project_path}/${project_name}.xcworkspace"
else # 项目中不存在 workspace
workspace_path="${project_path}/${project_name}.xcodeproj"
fi # scheme名称
scheme_name=$(/usr/libexec/PlistBuddy -c "print scheme_name" ${setting_path}) # 项目版本
project_version=$(/usr/libexec/PlistBuddy -c "print project_version" ${setting_path}) # 开发者账号
dev_account=$(/usr/libexec/PlistBuddy -c "print dev_account" ${setting_path}) # 开发者密码
dev_password=$(/usr/libexec/PlistBuddy -c "print dev_password" ${setting_path}) # 配置打包样式:Release/ad-hoc/Debug
configuration=$(/usr/libexec/PlistBuddy -c "print configuration" ${setting_path}) # 发布地址:蒲公英->PGY,苹果->APPStore, fir.im->FI
upload_address=$(/usr/libexec/PlistBuddy -c "print upload_address" ${setting_path}) # ipa包名称:项目名+版本号+打包类型
ipa_name=$(/usr/libexec/PlistBuddy -c "print ipa_name" ${setting_path}) # ipa包路径
ipa_path2=$(/usr/libexec/PlistBuddy -c "print ipa_path" ${setting_path})/${now}
ipa_path="${ipa_path2}-V${project_version}-${upload_address}" # 打包配置plist文件路径 (初始化)
plist_path=$(/usr/libexec/PlistBuddy -c "print plist_path" ${setting_path}) # 编译build路径
archive_path="${ipa_path}/${project_name}.xcarchive" # 上传到蒲公英设置
user_key=$(/usr/libexec/PlistBuddy -c "print user_key" ${setting_path})
api_key=$(/usr/libexec/PlistBuddy -c "print api_key" ${setting_path})
password=$(/usr/libexec/PlistBuddy -c "print password" ${setting_path}) # 上传fir.im 设置
fir_token=$(/usr/libexec/PlistBuddy -c "print fir_token" ${setting_path}) #打包方式配置,以及相应的需求配置
if [ ${upload_address} == "APPStore" ];then # 发布到 AppStore 配置 Release
configuration="Release"
plist_path=${project_path}/exportAppstore.plist
elif [ ${upload_address} == "PGY" ] ||[ ${upload_address} == "FI" ];then # 发布到第三方平台可 配置 Release、Debug
if [ ${configuration} == "Release" ];then
plist_path=${project_path}/exportAdHoc.plist
else
plist_path=${project_path}/exportDevelopment.plist
fi
else # 只打包,不发布到任何平台
if [ ${configuration} == "Release" ];then
plist_path=${project_path}/exportAppstore.plist
else
plist_path=${project_path}/exportDevelopment.plist
fi
fi echo '=============正在清理工程============='
xcodebuild clean -configuration ${configuration} -quiet || exit echo '清理完成-->>>--正在编译工程:'${configuration} # 通过workspace方式打包
if [ -d "./${project_name}.xcworkspace" ];then # 项目中存在workspace
xcodebuild archive -workspace ${workspace_path} -scheme ${scheme_name} \
-configuration ${configuration} \
-archivePath ${archive_path} -quiet || exit
else #通过xcodeproj 方式打包
xcodebuild archive -project ${workspace_path} -scheme ${scheme_name} \
-configuration ${configuration} \
-archivePath ${archive_path} -quiet || exit
fi # 检查是否构建成功(build)
if [ -d "$archive_path" ] ; then
echo '=============项目构建成功============='
else
echo '=============项目构建失败============='
exit
fi echo '编译完成-->>>--开始ipa打包'
xcodebuild -exportArchive -archivePath ${archive_path} \
-configuration ${configuration} \
-exportPath ${ipa_path} \
-exportOptionsPlist ${plist_path} \
-quiet || exit if [ -e ${ipa_path}/${ipa_name}.ipa ]; then
echo '=============ipa包导出成功============='
open $ipa_path
else
echo '=============ipa包导出失败============'
fi echo '打包ipa完成-->>>--开始发布ipa包' if [ ${upload_address} == "APPStore" ];then # 发布到APPStore
echo '发布ipa包到 =============APPStore============='
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
"$altoolPath" --validate-app -f ${ipa_path}/${ipa_name}.ipa -u ${dev_account} -p ${dev_password} -t ios --output-format xml
"$altoolPath" --upload-app -f ${ipa_path}/${ipa_name}.ipa -u ${dev_account} -p ${dev_password} -t ios --output-format xml if [ $? = ];then
echo "=============提交AppStore成功 ============="
else
echo "=============提交AppStore失败 ============="
fi elif [ ${upload_address} == "PGY" ];then # 发布到蒲公英平台
echo '发布ipa包到 =============蒲公英平台============='
curl -F "file=@${ipa_path}/${ipa_name}.ipa" -F "uKey=${user_key}" -F "_api_key=${api_key}" -F "password=${password}" https://www.pgyer.com/apiv1/app/upload if [ $? = ];then
echo "=============提交蒲公英成功 ============="
else
echo "=============提交蒲公英失败 ============="
fi elif [ ${upload_address} == "FI" ];then # 发布到fir.im 平台
echo '发布ipa包到 =============fir.im平台============'
# 需要先在本地安装 fir 插件,安装fir插件命令: gem install fir-cli
fir login -T ${fir_token} # fir.im token
fir publish ${ipa_path}/${ipa_name}.ipa if [ $? = ];then
echo "=============提交fir.im成功 ============="
else
echo "=============提交fir.im失败 ============="
fi
else # 未配置发布地址
echo "=============未发布 ipa包(打包方式:$configuration) 到任何平台============="
fi # 输出总用时
echo "执行耗时: ${SECONDS}秒" exit

me测试项目

#!/bin/sh
#计时
SECONDS=
# 项目名称
project_name='AudioVideo'
# 项目路径
project_path='/Users/xueshan1/Desktop/AudioVideo/AudioVideo' # workspace/xcodeproj 路径(根据项目是否使用cocoapod,确定打包的方式)
if [ -e "${project_path}/${project_name}.xcworkspace" ];then
workspace_path="${project_path}/${project_name}.xcworkspace"
else
workspace_path="${project_path}/${project_name}.xcodeproj"
fi # scheme名称
scheme_name='AudioVideo'
# 项目版本
project_version='1.2'
# 开发者账号
dev_account=''
# 开发者密码
dev_password=''

 api_key=''
 issuer_id=''

# 配置打包样式:Release/ad-hoc/Debug
configuration='Release'
# 发布地址:蒲公英->PGY,苹果->APPStore, fir.im->FI
upload_address='APPStore'
# upload_address='PGY'
# 编译build路径
archive_path="/Users/xueshan1/Desktop/AudioVideo打包/Test.xcarchive"
# ipa包名称:项目名+版本号+打包类型
ipa_name='AudioVideo'
# ipa包路径
ipa_path2='/Users/xueshan1/Desktop/AudioVideo打包/ipa'
ipa_path="${ipa_path2}-V${project_version}-${upload_address}"
ipa_pathIPA=${ipa_path}/${ipa_name}.ipa # 打包配置plist文件路径
plist_path='/Users/xueshan1/Desktop/AudioVideo/AudioVideo/exportAppstore.plist' #打包方式配置,以及相应的需求配置
if [ ${upload_address} == "APPStore" ];then
configuration="Release"
plist_path=${project_path}/exportAppstore.plist
else
# if [ ${configuration} == "Release" ];then
# plist_path=${project_path}/exportAppstore.plist
# else
plist_path=${project_path}/exportDevelopment.plist
# fi
fi echo '=============正在清理工程============='
echo $configuration xcodebuild \
clean -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${configuration} -quiet || exit echo '清理完成-->>>--正在编译工程:'${workspace_path}
# build
if [ -d ${workspace_path} ];then
xcodebuild archive -workspace ${workspace_path} \
-scheme ${scheme_name} \
-configuration ${configuration} \
-archivePath ${archive_path} -quiet || exit
else
echo 'workspace 不存在'
fi # 检查是否构建成功(build)
if [ -d ${archive_path} ] ; then
echo '=============项目 build 成功============='
else
echo '=============项目 build 失败============='
exit
fi # exprot
echo '编译完成-->>>--开始ipa打包'
xcodebuild -exportArchive -archivePath ${archive_path} \
-configuration ${configuration} \
-exportPath ${ipa_path} \
-exportOptionsPlist ${plist_path} \
-quiet || exit if [ -e ${ipa_pathIPA} ]; then
echo '=============ipa包导出成功============='
open $ipa_path
else
echo '=============ipa包导出失败============'
echo "${ipa_pathIPA}"
exit
fi echo "-->>>--开始发布ipa包 ${ipa_pathIPA}" if [ ${upload_address} == "APPStore" ];then # 发布到APPStore
echo '发布ipa包到 =============APPStore=============' altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
# "$altoolPath" --validate-app -f ${ipa_pathIPA} -u ${dev_account} -p ${dev_password} -t ios --output-format xml
# "$altoolPath" --upload-app -f ${ipa_pathIPA} -u ${dev_account} -p ${dev_password} -t ios --output-format xml   #新命令, 使用api_key
xcrun altool --validate-app -f ${ipa_pathIPA} -u ${dev_account} -p ${dev_password} -t ios --output-format xml  --apiKey ${api_key} --apiIssuer ${issuer_id}
xcrun altool --upload-app -f ${ipa_pathIPA} -u ${dev_account} -p ${dev_password} -t ios --output-format xml  --apiKey ${api_key} --apiIssuer ${issuer_id}   if [ $? = ];then
echo "=============提交AppStore成功 ============="
else
echo "=============提交AppStore失败 ============="
fi else # 蒲公英
echo '发布ipa包到 =============蒲公英============='
curl -F "file=@${ipa_pathIPA}" -F "_api_key=eb4171585a2f2df5674db48745520bc0" -F "password=maxueshan123" -F "buildInstallType=2" -F "buildPassword=2" https://www.pgyer.com/apiv2/app/upload if [ $? = ];then
echo "=============提交蒲公英成功 ============="
else
echo "=============提交蒲公英失败 ============="
fi fi # 输出总用时
echo "执行耗时: ${SECONDS}秒" exit

上传验证ipa包时候报错,  将开发者账号密码替换成 秘钥的方式

参考1

参考2

xcodebuild 自动化打包的更多相关文章

  1. XCode 自动化打包总结

    最近一个礼拜折腾xcode 中ipa 自动化打包,对我来说也说是磕磕碰碰.毕竟对mac下的命令行模式完全不熟悉.而且我们的项目是基于cordova的一个项目. 之前我自己对cordova 项目的命令行 ...

  2. iOS Jenkins 自动化打包构建

    前言 在测试app项目过程中,通常都是需要开发打测试包给到测试,但是无论是iOS还是Android的打包过程都是相当漫长的,频繁的回归测试需要频繁的打包,对于开发同学影响还是蛮大的.因此在这种情况下, ...

  3. IOS自动化打包介绍

    IOS自动化打包介绍  标签: app打包 , Ios打包 , iphone打包 , iphone自动化打渠道包    分类:无线客户端技术, 贴吧技术 摘要 随着苹果手持设备用户的不断增加,ios应 ...

  4. Jenkins实现Android自动化打包

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/77102359 本文出自[赵彦军的博客] 1.Tomcat 进入 https://t ...

  5. 自动化打包 Jenkins 持续集成 Git Gradle MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  6. ios实现fastlane自动化打包

    终于抽出时间来学习自动化打包了,app在测试阶段一天总会经历好几次的打包,每次打包真是身心疲惫,刚打完的包说不定就被测试妹子反应还要微调什么地方,我就真的有气没法出,打一次包怎么也得浪费十几分钟,还不 ...

  7. gulp自动化打包及静态文件自动添加版本号

    前端自动化打包发布已是一种常态,尤其在移动端,测试过程中静态资源的缓存是件很头疼的事情,有时候明明处理的bug测试还是存在,其实就是缓存惹的祸,手机不比pc浏览器,清理缓存还是有点麻烦的.所以自动化实 ...

  8. Jenkins+ Xcode+ 蒲公英 实现IOS自动化打包和分发

    Jenkins+ Xcode+ 蒲公英 实现IOS自动化打包和分发 直接入正题: Screen Shot 2015-09-18 at 16.56.20.png Mac上安装Jekins jekins下 ...

  9. 使用Jenkins集成和自动化打包资料

    1.手把手教你利用Jenkins持续集成iOS项目 http://www.jianshu.com/p/41ecb06ae95f 2.Jenkins+ Xcode+ 蒲公英 实现IOS自动化打包和分发 ...

随机推荐

  1. numpy.meshgrid的理解以及3D曲面图绘制(梯度下降法实现过程)

    相关概念: 1.x向量和y向量 import numpy as np import matplotlib.pyplot as plt x = np.array([[0,1,2,3], [0,0,0,0 ...

  2. ubantu 安装软件

    一.解压后bin文件夹里有setup.py 进入到setup.py的目录,执行命令: sudo python3 setup.py install 二.以.whl结尾的文件 直接运行命令: sudo p ...

  3. java_第一年_JavaWeb(8)

    前面说到,JSP在运行时会被编译成Servlet源代码,通过_jspServlet方法处理请求,此时该方法会传递和提供9个与web开发相关的对象进行使用,开发人员在JSP页面通过对这些变量即可引用这9 ...

  4. [fw]Linux下tty/pty/pts/ptmx详解

    基本概念: 1> tty(终端设备的统称):tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东 ...

  5. II play with GG

    https://ac.nowcoder.com/acm/contest/338/I 题解:首先轮到出手的时候如果在(0,0)上肯定是输的,而(0,1)(1,0)(0,2)(2,0)(1,1)肯定是赢的 ...

  6. 使用Anaconda3安装tensorflow,opencv,使其可以在spyder中运行

    使用Anaconda5.0.0 1.首选无论你是在cmd键入python,还是在Anaconda Prompt键入python,显示的都是Python3.6.然而在Spyder(tensorflow) ...

  7. 函数异步模拟实现ajax

    //模拟ajax function getData(callback){ setTimeout(function(){ var name='leo' callback(name) },1000) re ...

  8. 20180209-json&pickle&shelve模块

    什么是序列化? 序列化就是把内存里的数据类型转成字符串,以使其能够存储到硬盘中或在网络中传输到远程,因为硬盘和网络传输时只接收bytes 用于序列化的两个模块 1. json,用于字符串和python ...

  9. Django组件——Cookie与session相关

    一,会话跟踪技术 1 什么是会话跟踪技术我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而1 ...

  10. 【LeetCode】链表 linked list(共34题)

    [2]Add Two Numbers (2018年11月30日,第一次review,ko) 两个链表,代表两个整数的逆序,返回一个链表,代表两个整数相加和的逆序. Example: Input: ( ...