问题
使用 Jenkins 来做 iOS 项目的持续集成,升级 Xcode 9 之后,编译完成之后打包会一直报如下所示的错误:
error: exportArchive: "APPNAME.app" requires a provisioning profile with the Push Notifications feature.
Error Domain=IDEProvisioningErrorDomain Code=9 ""APPNAME.app" requires a provisioning profile with the Push Notifications feature." UserInfo={NSLocalizedDescription="APPNAME.app" requires a provisioning profile with the Push Notifications feature., NSLocalizedRecoverySuggestion=Add a profile to the "provisioningProfiles" dictionary in your Export Options property list.}
** EXPORT FAILED **
Failed to build /Users/Tolecen/.jenkins/workspace/APPNAME/build/APPNAME_release.ipa
Build step 'Xcode' marked build as failure
Finished: FAILURE
原因
因为 Xcode 9 默认不允许访问钥匙串的内容,必须要设置 allowProvisioningUpdates 才会允许,但是由于 Xcode integration 插件封闭,并不能对其进行修改加上这个属性,所以决定使用 Shell 脚本代替插件
解决方案
将 Jenkins 项目里的 Xcode integration 构建步骤去掉,使用下面所示的命令:
如果是 project 的项目,那就将下面第一段的命令中 -workspace ${PROJECT_NAME}.xcworkspace 修改为 -workspace ${PROJECT_NAME}.xcodeproj 即可。
# clean
echo "================= Clean一下 ================="
xcodebuild clean -workspace ${PROJECT_NAME}.xcworkspace \
-configuration ${CONFIGURATION} \
-target ${CURRENT_SHEME} \
#-alltargets
echo "================= Clean一下 Over ================="
# archive
echo "============== archive =================="
xcodebuild archive -workspace ${PROJECT_NAME}.xcworkspace \
-scheme ${CURRENT_SHEME} \
-configuration ${CONFIGURATION} \
CFBundleVersion=${BOUNDLE_VERSION} \
-destination generic/platform=ios \
-archivePath build/${CURRENT_SHEME}.xcarchive \
CODE_SIGN_IDENTITY="${__signingIdentity}"
# export ipa
echo "+++++++++++++++++ exportArchive +++++++++++++++++"
xcodebuild -exportArchive -archivePath build/${CURRENT_SHEME}.xcarchive \
-exportPath build/${CURRENT_SHEME}\
-destination generic/platform=ios\
-exportOptionsPlist ${ExportOptionsPlistPath}\
-allowProvisioningUpdates
注意ExportOptions.plist配置,这个文件如下所示:
<?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>compileBitcode</key>
<false/>
<key>method</key>
<string>enterprise</string>
<key>provisioningProfiles</key>
<dict>
<key>com.houmanager.enterprise.test</key>
<string>com.houmanager.enterprise.test</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>5XXXXXXXXXXXHM</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
如果不知道怎么填写,手动用Xcode9打包,导出文件中会有ExportOptions.plist
直接复制到指定路径或者手动copy即可。