xcodebuild自動打包,發(fā)布應用

簡介

在iOS持續(xù)集成的過程中,簽名打包這一部分,就是對原生指令進行了封裝, 將常用的參數名簡化, 支持全部的自帶參數及設置, 同時輸出符號表 dSYM 文件, 并且支持直接從相關 repo 直接編譯打包.因此熟悉一下xcodebuild還是很有必要的。

在終端輸入man xcodebuild,可以看到Description里面有介紹用法。

打包流程

Archive包

xcodebuild archive -workspace 項目名稱.xcworkspace 
                       -scheme 項目名稱 
                       -configuration 構建配置 
                       -archivePath archive包存儲路徑 
                       CODE_SIGN_IDENTITY=證書 
                       PROVISIONING_PROFILE=描述文件UUID

在這里證書,和描述文件的字段,可要可不要,它會根據xcode去匹配

證書對應內容:
在鑰匙串找到對應證書把加粗部分的標題復制出來即可

DEA480DF-1E62-427E-92A3-2D8556D5D63A.png

描述文件UUID:
首先到描述文件路徑:

/Users/用戶名/Library/MobileDevice/Provisioning Profiles 

在終端下解密描述文件

security cms -D -i xxxx.mobileprovision

可以找到TeamName,UUID,等對應的value值,注意要 在CODE_SIGN_IDENTITY,PROVISIONING_PROFILE賦值時要加“”號

DBD1245A-4FE3-4459-A548-3DAEE83916E9.png

導出ipa包

xcodebuild -exportArchive -archivePath archive文件的地址.xcarchive 
                          -exportPath 導出的文件夾地址 
                          -exportOptionsPlist exprotOptionsPlist.plist 
                          CODE_SIGN_IDENTITY=證書 
                          PROVISIONING_PROFILE=描述文件UUID

同樣的,證書和描述文件的參數可要可不要,exportOptionsPlist是plist文件,我們可以用xcode創(chuàng)建一個,在里面可以配置參數,我的如下:

image.png

我的命令:

350A6141-A444-473F-8968-D0E00B0BF3EF.png

使用xcodebuild exportOptionsPlist -h 查看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, package, ad-hoc, 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.

上傳

1.測試包:

可以上傳到fir,蒲公英等網站,以fir為例,
首先需要一個注冊一個fir賬號,從里面可以獲取一個apitoken
安裝fir(fir命令參考)

 ruby -v  // > 1.9.3
 gem install fir-cli

登錄fir

fir login   //此時會讓你輸入apitoken
fir me  //獲取賬號信息

發(fā)布應用到fir

fir publish  ipa包全路徑

發(fā)布成功后,終端會輸出一個路徑,這個就是應用發(fā)布后的路徑,復制訪問即可.

2.正式包

altool:Application Loader的命令行工具用來驗證并上傳你的應用程序二進制文件到App Store
altool工具路徑:

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

設置別名

在~/.bash_profile 中設置別名
alias altool='/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool'

設置別名后在終端
輸入 source ~/.bash_profile
再輸入 altool  就會有它的一些用法提示,否則就是設置別名失敗了 

altool用法

驗證 ipa
altool --validate-app -f file -u username [-p password] [--output- format xml]
上傳 ipa
altool --upload-app -f file -u username [-p password] [--output- format xml]

具體參數:

--validate-app
您要驗證的應用程序。
--upload-app
您要上傳的應用程序。
-f file
您正在驗證或上傳的應用程序的路徑和文件名。
-u username
您的用戶名。
-p password
您的用戶密碼。
--output-format [xml | normal]
您要 Application Loader 以結構化的 XML 格式還是非結構化的文本格式返回輸出信息。Application Loader 默認以文本格式返回輸出信息。

我的驗證命令如下:

altool -validate-app -f 路徑.ipa   -u  用戶名  -p 密碼 -t ios

不出意外就可以得到一個成功的驗證結果,我用的是以前上架過的包,得到的驗證是已經存在這個包的錯誤提示

屏幕快照 2017-08-29 下午2.46.35.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容