主要是为了打包的时候不占用xcode的时候,让他自己打包就行了
2.创建一个后缀名是.plist文件我用的文件名就是exportTest.plish(文件在下面)
3.把.sh和.plist这两个文件放在和.xcodeproj这个目录同级
4.用命令cd 到你项目的根目录
5.再输入 ./shell.sh
6.选择你你要打包的模式(目前只测试了2:打包上传蒲公英 3:不上传打包)
就让他自己运行就好了
#需要修改的地方【*需要修改*】 #判断是否有IPADir文件夹 没有就创建 if [ ! -d ./IPADir ]; then mkdir -p IPADir; fi #工程绝对路径 project_path=$(cd `dirname $0`; pwd) #工程名 将*替换成自己的工程名【*需要修改*】 project_name=* #scheme名 将*替换成自己的sheme名【*需要修改*】 scheme_name=* #scheme名 将*替换成自己的product_name名(如果和targets一样就和scheme_name一样)【*需要修改*】 product_name=* #蒲公英上的API Key 【*需要修改*】 apiKey="" #如果不是选择1上传Appstore下面两个就不需要修改 #appstore AppleID的账号 【*需要修改*】 appstore_name="" #appstore AppleID密码 【*需要修改*】 appstore_pwd="" #打包模式 Debug/Release development_mode=Release #build文件夹路径 build_path=${project_path}/build #plist文件所在路径 -- 打包导出ipa exportOptionsPlistPath=${project_path}/exportTest.plist #导出.ipa文件所在路径 exportIpaPath=${project_path}/IPADir/${development_mode} echo "请输入数字选择打包模式 ? [ 1:上传app-store 2:打包上传蒲公英 3:不上传打包] " read number while([[ $number != 1 ]] && [[ $number != 2 ]] && [[ $number != 3 ]]) do echo "选择错误请输入 1 or 2 or 3" echo "请输入数字选择打包模式 ? [ 1:上传app-store 2:打包上传蒲公英 3:不上传打包] " read number done if [ $number == 1 ];then exportOptionsPlistPath=${project_path}/exportAppstore.plist echo "----------您选择的是上传app-store \n" elif [ $number == 2 ];then exportOptionsPlistPath=${project_path}/exportTest.plist echo "----------你选择的是打包上传蒲公英 \n" else exportOptionsPlistPath=${project_path}/exportTest.plist echo "----------你选择的是不上传打包 \n\n" fi #检查apikey if [ -z "$apiKey" ] && [ $number != 3 ]; then echo "上传蒲公英apiKey不能为空" exit 1 fi echo '///-----------' echo '/// 删除之前的编译文件夹【build】' echo '///-----------' rm -rf build || exit echo '///-----------' echo '/// 正在清理工程' echo '///-----------' xcodebuild \ clean -configuration ${development_mode} -quiet || exit echo '///--------' echo '/// 清理完成' echo '///--------' echo '' echo '///-----------' echo '/// 正在编译工程:'${development_mode} echo '///-----------' xcodebuild \ archive -workspace ${project_path}/${project_name}.xcworkspace \ -scheme ${scheme_name} \ -configuration ${development_mode} \ -archivePath ${build_path}/${project_name}.xcarchive -quiet || exit echo '///--------' echo '/// 编译完成' echo '///--------' echo '' echo '///----------' echo '/// 开始ipa打包' echo '///----------' xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \ -configuration ${development_mode} \ -exportPath ${exportIpaPath} \ -exportOptionsPlist ${exportOptionsPlistPath} \ -quiet || exit if [ -e $exportIpaPath/$product_name.ipa ]; then echo '///----------' echo '/// 打包ipa完成' echo '///----------' echo '' else echo '///-------------' echo '/// 打包ipa失败 ' echo '///-------------' exit 1 fi #打开ipa文件夹 open $exportIpaPath echo '///------------' echo '/// --- 打开IPA文件夹 ' echo '///------------' if [ $number == 1 ];then #验证并上传到App Store altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" "$altoolPath" --validate-app -f ${exportIpaPath}/${product_name}.ipa -u ${appstore_name} -p ${appstore_pwd} -t ios --output-format xml "$altoolPath" --upload-app -f ${exportIpaPath}/${product_name}.ipa -u ${appstore_name} -p ${appstore_pwd} -t ios --output-format xml elif [ $number == 2 ];then echo "\n\n\033[32m -----------------------上传到蒲公英----------------------- \033[0m\n\n\n" IPAPATHOUT=$exportIpaPath/$product_name.ipa echo '\n\033[34m 上传到蒲公英ipa地址======\033[0m'${IPAPATHOUT} uploadCommand() { result=$(eval $@) } # --------------------------------------------------------------- # 获取上传凭证 # --------------------------------------------------------------- echo '\n\033[34m -----------------------获取上传凭证-----------------------\033[0m\n' uploadCommand "curl -s -F '_api_key=${apiKey}' -F 'buildType="ipa"' http://www.pgyer.com/apiv2/app/getCOSToken"; [[ "${result}" =~ \"endpoint\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && endpoint=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'` [[ "${result}" =~ \"key\":\"([\.a-z0-9]+)\" ]] && key=`echo ${BASH_REMATCH[1]}` [[ "${result}" =~ \"signature\":\"([\=\&\_\;A-Za-z0-9\-]+)\" ]] && signature=`echo ${BASH_REMATCH[1]}` [[ "${result}" =~ \"x-cos-security-token\":\"([\_A-Za-z0-9\-]+)\" ]] && x_cos_security_token=`echo ${BASH_REMATCH[1]}` if [ -z "$key" ] || [ -z "$signature" ] || [ -z "$x_cos_security_token" ] || [ -z "$endpoint" ]; then echo "\033[31m -----------------------获取凭证失败-----------------------\033[0m" exit 1 else echo "\n\n\033[32m -----------------------获取凭证成功----------------------- \033[0m\n\n\n" echo "\033[32m tokenKey:${key} \033[0m" echo "\033[32m signature:${signature} \033[0m" echo "\033[32m x_cos_security_token:${x_cos_security_token} \033[0m" echo "\033[32m endpoint:${endpoint} \033[0m" fi # --------------------------------------------------------------- # 上传文件到蒲公英 # --------------------------------------------------------------- echo '\n\033[34m -----------------------上传文件到蒲公英-----------------------\033[0m\n' file_name=${IPAPATHOUT*/} uploadCommand "curl -o /dev/null -w '%{http_code}' \ --form-string 'key=${key}' \ --form-string 'signature=${signature}' \ --form-string 'x-cos-security-token=${x_cos_security_token}' \ --form-string 'x-cos-meta-file-name=${file_name}' \ -F 'file=@${IPAPATHOUT}' ${endpoint}" # if http code != 204, upload failed if [ $result -ne 204 ]; then echo "\033[31m -----------------------上传文件失败-----------------------\033[0m" exit 1 else echo "\n\n\033[32m -----------------------文件已上传完毕----------------------- \033[0m\n\n\n" fi # --------------------------------------------------------------- # 检查上传结果 # --------------------------------------------------------------- echo '\n\033[34m -----------------------检查上传结果-----------------------\033[0m\n' for i in {1..60}; do uploadCommand "curl -s http://www.pgyer.com/apiv2/app/buildInfo?_api_key=${apiKey}\&buildKey=${key}" [[ "${result}" =~ \"code\":([0-9]+) ]] && code=`echo ${BASH_REMATCH[1]}` [[ "${result}" =~ \"buildIdentifier\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && buildIdentifier=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'` [[ "${result}" =~ \"buildShortcutUrl\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && buildShortcutUrl=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'` [[ "${result}" =~ \"buildQRCodeURL\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && buildQRCodeURL=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'` currentTime=$(date +"%Y-%m-%d %H:%M:%S") if [ $code -eq 0 ]; then echo "\033[32m -----------------------上传文件成功----------------------- \033[0m" echo "\033[32m 应用包名:${buildIdentifier} \033[0m" echo "\033[32m 应用短链接:https://www.pgyer.com/${buildShortcutUrl} \033[0m" echo "\033[32m 应用上传时间:${currentTime} \033[0m" echo "\033[32m 本次上传二维码地址:${buildQRCodeURL} \033[0m" break else sleep 1 fi done echo '\n\n-----------------------正在删除打包后的编译文件和配置文件(所有自动打包的文件包括本脚本)-----------------------' echo '-----------------------删除文件夹 【build】-----------------------' rm -rf build || exit echo '-----------------------【build 删除成功】-----------------------' echo '-----------------------删除文件夹 【IPADir】-----------------------' rm -rf IPADir || exit echo '-----------------------【IPADir 删除成功】-----------------------' echo '-----------------------删除文件 【exportTest.plist】-----------------------' rm -rf exportTest.plist || exit echo '-----------------------【exportTest.plist 删除成功】-----------------------' echo '-----------------------删除文件 【shell.sh】-----------------------' rm -r shell.sh || exit echo '-----------------------【shell.sh 删除成功】-----------------------' else echo '-----------------------不上传只打包end-----------------------' fi exit 0
exportTest.plish代码如下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>signingStyle</key> <string>automatic</string> <key>iCloudContainerEnvironment</key> <string>Production</string> <key>method</key> <string>ad-hoc</string> <key>compileBitcode</key> <false/> </dict> </plist>
今天的文章
iOS shell 自动打包IPA上传蒲公英分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/78513.html