当前位置: 首页>移动开发>正文

xcode15打包 ios12启动闪退 xcode自动打包

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 == 1 ]]; 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=0

#取当前时间字符串添加到文件结尾
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 1
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 [ $? = 0 ];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 [ $? = 0 ];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 [ $? = 0 ];then
    echo "=============提交fir.im成功 ============="
    else
    echo "=============提交fir.im失败 ============="
    fi
else # 未配置发布地址
    echo "=============未发布 ipa包(打包方式:$configuration) 到任何平台============="
fi

# 输出总用时
echo "执行耗时: ${SECONDS}秒"

exit 0

 

me测试项目

#!/bin/sh
#计时
SECONDS=0
# 项目名称
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 1
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 1
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 [ $? = 0 ];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 [ $? = 0 ];then
    echo "=============提交蒲公英成功 ============="
    else
    echo "=============提交蒲公英失败 ============="
    fi
    
fi

# 输出总用时
echo "执行耗时: ${SECONDS}秒"



exit 0

 

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


https://www.xamrdz.com/mobile/4gv1963950.html

相关文章: