Xcode 9 在 Jenkins 自动打包脚本 中使用 Xcode integration 插件打包失败的原因

问题

使用 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 PROJECTNAME.xcworkspaceworkspace{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配置,这个文件如下所示:



<plist version="1.0">
<dict>
    <key>compileBitcodekey>
    <false/>
    <key>methodkey>
    <string>enterprisestring>
    <key>provisioningProfileskey>
    <dict>
        <key>com.houmanager.enterprise.testkey>
        <string>com.houmanager.enterprise.teststring>
    dict>
    <key>signingCertificatekey>
    <string>iPhone Distributionstring>
    <key>signingStylekey>
    <string>manualstring>
    <key>stripSwiftSymbolskey>
    <true/>
    <key>teamIDkey>
    <string>5XXXXXXXXXXXHMstring>
    <key>thinningkey>
    <string><none>string>
dict>
plist>

如果不知道怎么填写,手动用Xcode9打包,导出文件中会有ExportOptions.plist

直接复制到指定路径或者手动copy即可。

你可能感兴趣的:(iOS)