iOS持续集成-Xcodebuild命令

xiaoxiao2021-02-28  106

为什么

打包一般使用GUI操作进行。但是对于复杂工程还是繁琐。比如同一个工程对应多个target,多个scheme,多个证书。另外对于持续化集成还不足够,所以需要使用Xcodebuild进行脚本化。

Tips:针对Xcode进行过重签名,in-house包会失败。


使用

以下针对xcode8,xcworkspace文件进行打包。

简单来说打包分为三步:

1、 清理 - clean

xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme

2、 归档 - archive

xcodebuild archive -workspace MyWorkspace.xcworkspace -scheme MyScheme

3、 导出 - export

xcodebuild -exportArchive -archivePath MyMobileApp.xcarchive -exportPath ExportDestination -exportOptionsPlist 'exportPlist.plist'

需要参数

@required

bundle_identifier development_team code_sign_identity provisioning_profile

@optional

app_group extension_bundle_identifier extension_provisioning_profile

相关问题

多环境

1、PROJECT -> Info -> Configurations 中添加configuration。 2、PROJECT -> Build Settings -> Preprocessor Macros 中添加宏。 如:DEBUG_LOG=1 3、在代码中判断宏,配置不同环境变量:

#ifdef DEBUG_LOG #endif

4、增加scheme对应configuration。 5、针对scheme打包即是针对环境打包。


多工程

一个工程对应一个scheme,针对scheme打包即是针对工程打包。


不同证书

打包时设置bundle_identifier、development_team、code_sign_identity、provisioning_profile等参数即可。


导出命令失败 error: exportArchive: No applicable devices found. Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo={NSLocalizedDescription=No applicable devices found.} ** EXPORT FAILED **

解决方案:将xcodebuild替换为xcbuild.sh。xcbuild.sh如下:

#!/usr/bin/env bash --login [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" rvm use system xcodebuild "$@"
exportPlist相关参数

简单来说method中enterprise为企业包,app-store为App Store发布包。

<?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>method</key> <string>app-store</string> <key>uploadBitcode</key> <false/> <key>uploadSymbols</key> <false/> </dict> </plist>

对应参数详情

Available keys for -exportOptionsPlist: compileBitcode : Bool For non-App Store exports, should Xcode re-compile the app from bitcode? Defaults to YES. embedOnDemandResourcesAssetPacksInBundle : Bool For non-App Store exports, if the app uses On Demand Resources and this is YES, asset packs are embedded in the app bundle so that the app can be tested without a server to host asset packs. Defaults to YES unless onDemandResourcesAssetPacksBaseURL is specified. iCloudContainerEnvironment For non-App Store exports, if the app is using CloudKit, this configures the "com.apple.developer.icloud-container-environment" entitlement. Available options: Development and Production. Defaults to Development. manifest : Dictionary For non-App Store exports, users can download your app over the web by opening your distribution manifest file in a web browser. To generate a distribution manifest, the value of this key should be a dictionary with three sub-keys: appURL, displayImageURL, fullSizeImageURL. The additional sub-key assetPackManifestURL is required when using on demand resources. method : String Describes how Xcode should export the archive. Available options: app-store, ad-hoc, package, enterprise, development, and developer-id. The list of options varies based on the type of archive. Defaults to development. onDemandResourcesAssetPacksBaseURL : String For non-App Store exports, if the app uses On Demand Resources and embedOnDemandResourcesAssetPacksInBundle isn't YES, this should be a base URL specifying where asset packs are going to be hosted. This configures the app to download asset packs from the specified URL. teamID : String The Developer Portal team to use for this export. Defaults to the team used to build the archive. thinning : String For non-App Store exports, should Xcode thin the package for one or more device variants? Available options: <none> (Xcode produces a non-thinned universal app), <thin-for-all-variants> (Xcode produces a universal app and all available thinned variants), or a model identifier for a specific device (e.g. "iPhone7,1"). Defaults to <none>. uploadBitcode : Bool For App Store exports, should the package include bitcode? Defaults to YES. uploadSymbols : Bool For App Store exports, should the package include symbols? Defaults to YES.
设置plist

使用/usr/libexec/PlistBuddy命令,可进行增删查改,如:

/usr/libexec/PlistBuddy -c 'Set :method "app-store"' exportPlist.plist
extension打包

包含extension的项目,需要指定多个provisioning_profile。以下步骤适用于主工程和extension工程: 1、手动选择证书 2、Build Settings -> Product Bundle Identifier -> 清空release对应的value 3、Build Settings -> Provisioning Profile -> release对应的value改为$APP_PROFILE(extension改为$EXTENSION_PROFILE)`

tips:APP_PROFILE、EXTENSION_PROFILE均可自定义,如extension有多个自行改名区分。 打包的归档部分修改如下:

xcodebuild archive -workspace MyWorkspace.xcworkspace -scheme MyScheme DEVELOPMENT_TEAM=${development_team} CODE_SIGN_IDENTITY=${code_sign_identity} APP_PROFILE=${provisioning_profile} EXTENSION_PROFILE=${extension_provisioning_profile}

总结

脚本如下:

ios-build.sh

buildPath="yourbuildPath" scheme="yourscheme" package="yourpackage" develop_team="yourdevelop_team" code_sign_identity="yourcode_sign_identity" provisioning_profile="yourprovisioning_profile" extension_provisioning_profile="yourextension_provisioning_profile" ./xcbuild.sh clean -workspace ${package}.xcworkspace -scheme ${scheme} ./xcbuild.sh archive -workspace ${package}.xcworkspace -scheme ${scheme} -archivePath "${buildPath}/${package}.xcarchive" DEVELOPMENT_TEAM=${develop_team} CODE_SIGN_IDENTITY=${code_sign_identity} APP_PROFILE=${provisioning_profile} EXTENSION_PROFILE=${extension_provisioning_profile} ./xcbuild.sh -exportArchive -archivePath "${buildPath}/${package}.xcarchive" -exportPath "${buildPath}/${package}" -exportOptionsPlist exportPlist.plist

xcbuild.sh

#!/usr/bin/env bash --login [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" rvm use system xcodebuild "$@"

exportPlist.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>method</key> <string>app-store</string> <key>uploadBitcode</key> <false/> <key>uploadSymbols</key> <false/> </dict> </plist>

补充

Xcode11打包报错 使用旧版本编译系统打包 -UseModernBuildSystem=NO xcodebuild archive -workspace MyWorkspace.xcworkspace -scheme MyScheme DEVELOPMENT_TEAM=${development_team} CODE_SIGN_IDENTITY=${code_sign_identity} APP_PROFILE=${provisioning_profile} EXTENSION_PROFILE=${extension_provisioning_profile} -UseModernBuildSystem=NO

摘录

http://www.cocoachina.com/ios/20151104/14050.html http://help.apple.com/xcode/mac/8.3/#/dev04b3a04ba https://developer.apple.com/legacy/library/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html http://stackoverflow.com/questions/27973011/xcodebuild-different-provisioning-profile-for-target-dependency http://www.matrixprojects.net/p/xcodebuild-export-options-plist/ http://www.matrixprojects.net/p/xcodebuild-export-options-plist/ http://mjtsai.com/blog/2016/06/22/xcode-8-tips-and-issues/ http://stackoverflow.com/questions/27445649/xctool-build-with-today-extension http://www.jianshu.com/p/1cec79a7ab46 https://wearebase.com/blog/2016/provisioning-and-distributing-watchkit-apps/ http://www.it1me.com/it-answers?id=2664885&s=AD&ttl=Xcode+"Build+and+Archive"+from+command+line https://pewpewthespells.com/blog/migrating_code_signing.html https://www.jianshu.com/p/c3d7cd807c27

转载请注明原文地址: https://www.6miu.com/read-57096.html

最新回复(0)