升级Xcode9之后对于iOS打包一些shell的调整
升级到xcode9之后,苹果推荐所有的打包指令都需要使用xcodebuild来操作,原来的东西不能用了,重新来过吧。哎。
导出脚本需要配置一些签名证书相关的东西。先要准备如下一个plist文件.
<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
<dict>
<key>method</key>
<string>@method</string>
<key>provisioningProfiles</key>
<dict>
<key>com.szzc.szzc</key>
<string>@profile</string>
</dict>
<key>signingCertificate</key>
<string>@signcert</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true>
<key>teamID</key>
<string>@teamID</string>
<key>thinning</key>
<string><none></string>
<key>uploadBitcode</key>
<false>
<key>compileBitcode</key>
<false>
<key>uploadSymbols</key>
<true>
<key>embedOnDemandResourcesAssetPacksInBundle</key>
<false>
</false></true></false></false></true></dict>
</plist>
准备配置jenkins的一些参数化构建参数
下面脚本是动态地将参数配置到plist模板中来
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
method=sys.argv[1]
profile=sys.argv[2]
signcert=sys.argv[3]
teamID=sys.argv[4]
print 'params is:' + method + ' ' + profile + ' ' + signcert + ' ' + teamID
fileContent = '';
f = open('exportTemplate.plist')
file = f.readlines()
lineNumber = 0
for item in file:
lineNumber = lineNumber + 1
if '@method' in item:
item = item.replace('@method',method)
print 'find params in line :' + str(lineNumber)
if '@profile' in item:
item = item.replace('@profile',profile)
print 'find params in line :' + str(lineNumber)
if '@signcert' in item:
item = item.replace('@signcert',signcert)
print 'find params in line :' + str(lineNumber)
if '@teamID' in item:
item = item.replace('@teamID',teamID)
print 'find params in line :' + str(lineNumber)
fileContent += item
f.close()
# 写入文件
fo = open("exportTemplate.plist", "wb")
fo.write(fileContent);
# 关闭打开的文件
fo.close()
有了以上两个准备之后,下面开始进入主题吧。其实打包脚本核心就是两行shell而已。
#################auto change buildNumber####################
/usr/bin/xcrun agvtool new-version -all ${BUILD_NUMBER}
################build#######################################
xcodebuild -workspace zuche.xcworkspace -scheme zuche -configuration ${Scheme} -archivePath build/${Scheme}-iphoneos/zuche.xcarchive clean archive DEVELOPMENT_TEAM=${TeamID}
####################export#############################################################
cd ${WORKSPACE}/buildShell/
/usr/bin/python ${WORKSPACE}/buildShell/exportParams.py ${method} ${profile} ${signcert} ${TeamID}
cd ${WORKSPACE}/build/${Scheme}-iphoneos
xcodebuild -exportArchive -archivePath zuche.xcarchive -exportPath ${WORKSPACE}/zuche_${Scheme}_${BUILD_NUMBER}.ipa -exportOptionsPlist ${WORKSPACE}/buildShell/exportTemplate.plist
/usr/bin/zip -q -r ${WORKSPACE}/zuche_${Scheme}_${BUILD_NUMBER}.zip ${WORKSPACE}/build/${Scheme}-iphoneos/zuche.app.dSYM
###############################################################################
以上就可以生成最后的ipa和符号表了。