自动化打包上传

使用xcodebuild和xcrun打包签名

要构建Xcode项目,可以从包含项目的目录(即包含名称的目录)运行xcodebuild。如果在这个目录中有多个项目,则需要使用-项目来指示应该构建哪个项目。默认情况下,xcodebuild构建项目中列出的第一个目标,使用默认构建配置。目标的顺序是项目的属性,对项目的所有用户都是一样的。

总结一下:

需要在包含 name.xcodeproj 的目录下执行xcodebuild命令,且如果该目录下有多个 projects,那么需要使用-project指定需要 build 的项目。

在不指定 build 的 target 的时候,默认情况下会 build project 下的第一个 target

当 build workspace 时,需要同时指定-workspace和-scheme参数,scheme 参数控制了哪些 targets 会被 build 以及以怎样的方式 build。

配置好工程名、编译模式和路径、archive路径、输出打包后ipa的路径、证书名、签名文件。最重要不要遗漏打包需要的plist文件。

类似于手动打包流程:选择打包的模式、清理工程、构建项目、Archive、导出ipa包、上传到应用的托管平台对应的命令。


打包上传脚本

#!/bin/sh

echo"~~~~~~~~~~~~~~~~开始执行脚本~~~~~~~~~~~~~~~~"

echo"1 Release"

echo"2 Debug "

#开始时间

beginTime=`date +%s`

DATE=`date '+%Y-%m-%d-%T'`

#需要编译的targetName

TARGET_NAME="EtherSelected"

#编译模式工程默认有Debug Release

CONFIGURATION_TARGET = Debug

#编译路径

BUILDPATH=~/Desktop/xcArchiveList/${TARGET_NAME}_${DATE}

#archivePath

ARCHIVEPATH=${BUILDPATH}/${TARGET_NAME}.xcarchive

#输出的ipa目录

IPAPATH=~/Desktop/iosAPP_IPA

#证书名

CODE_SIGN_IDENTITY="iPhone Developer:小华小(5RE8Y42D4L)"

#描述文件

PROVISIONING_PROFILE_NAME="ethercapDev2"

#苹果账号

AppleID="xxxx"

AppleIDPWD="xxxx"

#导出ipa所需plist

ADHOCExportOptionsPlist=./ADHOCExportOptionsPlist.plist

AppStoreExportOptionsPlist=./AppStoreExportOptionsPlist.plist

EnterpriseExportOptionsPlist=./EnterpriseExportOptionsPlist.plist

ExportOptionsPlist=${EnterpriseExportOptionsPlist}

#EnterpriseExportOptionsPlist=${EnterpriseExportOptionsPlist}

#是否上传蒲公英

UPLOADPGYER=true

#是否上传AppStore

UPLOADAPPSTore=false

# echo "~~~~~~~~~~~~~~~~选择打包方式~~~~~~~~~~~~~~~~"

# echo "1 ad-hoc (默认)"

# echo "2 AppStore "

#读取用户输入并存到变量里

echo"~~~~~~~~~~~~~~~~请在5秒内进行输入否则会走默认环境~~~~~~~~~~~~~~~~"

read-t5-p"选择编译环境:\

"parameter

sleep1

method="$parameter"

echo"~~~~~~~~~~~~~~~~AD Hot~~~~~~~~~~~~~~~~"

#判读用户是否有输入

if[ -n"$method"]

then

if["$method"="1"]

then

PROVISIONING_PROFILE_NAME="ethercapDev2"

ExportOptionsPlist=${ADHOCExportOptionsPlist}

CONFIGURATION_TARGET="Release"

elif["$method"="2"]

then

PROVISIONING_PROFILE_NAME="ethercapDev2"

ExportOptionsPlist=${ADHOCExportOptionsPlist}

CONFIGURATION_TARGET="Debug"

else

PROVISIONING_PROFILE_NAME="ethercapDev2"

ExportOptionsPlist=${ADHOCExportOptionsPlist}

CONFIGURATION_TARGET="Debug"

echo"~~~~~~~~~~~~~用户输入条件无法识别~~~~~~~~~~~~~"

exit1

fi

else

PROVISIONING_PROFILE_NAME="ethercapDev2"

ExportOptionsPlist=${ADHOCExportOptionsPlist}

CONFIGURATION_TARGET="Debug"

echo"用户没有输入(默认Debug)...."

fi

echo"选择的:${CONFIGURATION_TARGET}环境-------------"

sleep1

if[ $UPLOADAPPSTore = false ]

then

# echo "~~~~~~~~~~~~~~~~是否上传蒲公英~~~~~~~~~~~~~~~~"

# echo "1不上传(默认)"

# echo "2上传"

# read para

# sleep 0.5

echo"~~~~~~~~~~~~~~~~上传蒲公英~~~~~~~~~~~~~~~~"

para="2"

if[ -n"$para"]

then

if["$para"="1"]

then

UPLOADPGYER=false

elif["$para"="2"]

then

UPLOADPGYER=true

else

echo"参数无效...."

exit1

fi

else

UPLOADPGYER=false

fi

fi

echo"~~~~~~~~~~~~~~~~开始编译~~~~~~~~~~~~~~~~~~~"

echo"~~~~~~~~~~~~~~~~开始清理~~~~~~~~~~~~~~~~~~~"

#清理避免出现一些莫名的错误

xcodebuild clean -workspace ${TARGET_NAME}.xcworkspace \

-configuration \

${CONFIGURATION} -alltargets

echo"~~~~~~~~~~~~~~~~开始构建~~~~~~~~~~~~~~~~~~~"

#开始构建

xcodebuild archive -workspace以太优选.xcworkspace \

-scheme ${TARGET_NAME} \

-archivePath ${ARCHIVEPATH} \

-configuration ${CONFIGURATION_TARGET} \

CODE_SIGN_IDENTITY="${CODE_SIGN_IDENTITY}"\

PROVISIONING_PROFILE="${PROVISIONING_PROFILE_NAME}"

#xcodebuild archive -workspace iOS-GMFinance-Fund.xcworkspace -scheme  iOS-GMFinance-Fund -configuration Debug -archivePath ${ARCHIVEPATH}

echo"~~~~~~~~~~~~~~~~检查是否构建成功~~~~~~~~~~~~~~~~~~~"

# xcarchive实际是一个文件夹不是一个文件所以使用-d判断

if[ -d"$ARCHIVEPATH"]

then

echo"构建成功......"

else

echo"构建失败......"

rm -rf $BUILDPATH

exit1

fi

endTime=`date +%s`

ArchiveTime="构建时间$[ endTime - beginTime ]秒"

echo"~~~~~~~~~~~~~~~~导出ipa~~~~~~~~~~~~~~~~~~~"

beginTime=`date +%s`

xcodebuild -exportArchive \

-archivePath ${ARCHIVEPATH} \

-exportOptionsPlist ${ExportOptionsPlist} \

-exportPath ${IPAPATH}

#xcodebuild -exportArchive -archivePath ${ARCHIVEPATH} -exportPath ${IPAPATH} -exportFormat ipa -exportProvisioningProfile "iOS Team Provisioning Profile: com.gomefinance.dev.test"

#xcodebuild -exportArchive -exportOptionsPlist ' + OPTIONS_LIST_PATH +' -archivePath ' + archive_dir() \

#+ ' -exportPath ' + ipa_dir() + ' PROVISIONING_PROFILE_SPECIFIER= ' + PROVISIONING_PROFILE

echo"~~~~~~~~~~~~~~~~检查是否成功导出ipa~~~~~~~~~~~~~~~~~~~"

IPAPATH=${IPAPATH}/${TARGET_NAME}.ipa

if[ -f"$IPAPATH"]

then

echo"导出ipa成功......"

else

echo"导出ipa失败......"

#结束时间

endTime=`date +%s`

echo"$ArchiveTime"

echo"导出ipa时间$[ endTime - beginTime ]秒"

exit1

fi

endTime=`date +%s`

ExportTime="导出ipa时间$[ endTime - beginTime ]秒"

#上传AppStore

if[ $UPLOADAPPSTore = true ]

then

altoolPath="/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"

${altoolPath} --validate-app \

-f ${IPAPATH} \

-u ${AppleID} \

-p ${AppleIDPWD} \

-t ios --output-format xml

if[ $? =0]

then

echo"~~~~~~~~~~~~~~~~验证ipa成功~~~~~~~~~~~~~~~~~~~"

${altoolPath} --upload-app \

-f ${IPAPATH} \

-u ${AppleID} \

-p ${AppleIDPWD} \

-t ios --output-format xml

if[ $? =0]

then

echo"~~~~~~~~~~~~~~~~提交AppStore成功~~~~~~~~~~~~~~~~~~~"

else

echo"~~~~~~~~~~~~~~~~提交AppStore失败~~~~~~~~~~~~~~~~~~~"

fi

else

echo"~~~~~~~~~~~~~~~~验证ipa失败~~~~~~~~~~~~~~~~~~~"

fi

else

#上传蒲公英

if[ $UPLOADPGYER = true ]

then

echo"~~~~~~~~~~~~~~~~上传ipa到蒲公英~~~~~~~~~~~~~~~~~~~"

curl -F"file=@$IPAPATH"\

-F"uKey=7cbdfa466b7d587b202dc8c11b53140a"\

-F"_api_key=d2ee43b3f321ecc7e9fdf11b3f85905a"\

http://www.pgyer.com/apiv1/app/upload--verbose

if[ $? =0]

then

echo"~~~~~~~~~~~~~~~~上传蒲公英成功~~~~~~~~~~~~~~~~~~~"

else

echo"~~~~~~~~~~~~~~~~上传蒲公英失败~~~~~~~~~~~~~~~~~~~"

fi

fi

fi

echo"~~~~~~~~~~~~~~~~配置信息~~~~~~~~~~~~~~~~~~~"

echo"开始执行脚本时间: ${DATE}"

echo"编译模式: ${CONFIGURATION_TARGET}"

echo"导出ipa配置: ${ExportOptionsPlist}"

echo"打包文件路径: ${ARCHIVEPATH}"

echo"导出ipa路径: ${IPAPATH}"

echo"$ArchiveTime"

echo"$ExportTime"

exit1

你可能感兴趣的:(自动化打包上传)