2016-09-11:
1.添加使用Python封裝打包命令的開源庫(kù)(最下面~)
2016-06-06:
1.經(jīng)過(guò)一輪測(cè)試之后, 發(fā)現(xiàn)文章有點(diǎn)錯(cuò)漏, 小修改一下, 增加命令四
每次要出包的時(shí)候, 總要打開
XCode
, 然后點(diǎn)擊Product-Archive
, 等待好幾分鐘的各種build, 然后還要手動(dòng)上傳到AppStore
, 甚至還要上傳到蒲公英
檀何、fir
等...
很久以前就看了很多關(guān)于iOS
自動(dòng)打包ipa
的文章, 看著感覺很簡(jiǎn)單, 但是因?yàn)橐恢睕]有AppleDeveloper
賬號(hào)可以給我用, 到了真的要搞自動(dòng)打包的時(shí)候, 才發(fā)現(xiàn)到處都是坑佳魔。
基本命令
- xcedebuild: 生成
Archive
、導(dǎo)出ipa
, 還有其它功能... - xcrun: 把
*.app
打包成ipa
, 還有其它功能...
基本使用
一. xcedebuild
打包Archive
文件
xcedebuild -workspace ${path to *.xcworkspace} -scheme ${scheme} -destination generic/platform=iOS archive -configuration Release ONLY_ACTIVE_ARCH=NO -archivePath ${export path *.xcarichive}
- -workspace 你的
*.xcworkspace
文件 - -scheme 項(xiàng)目文件里面的
scheme
- -archivePath 生成的
*.xcarichive
文件路徑
二. xcedebuild
從*.xcarchive
導(dǎo)出ipa
xcodebuild -exportArchive -exportFormat IPA -archivePath ${path to *.xcarchive} -exportPath ${export path *.ipa} -exportProvisioningProfile ${ProvisioningProfileName}
- -archivePath 你的
*.xcarchive
文件, 可以使用上一個(gè)命令導(dǎo)出 - -exportPath 導(dǎo)出的
ipa
路徑 - exportProvisioningProfile 你的Distribution發(fā)布證書的名稱(只需要名稱)
三. xcrun
打包ipa
xcrun -sdk iphoneos PackageApplication -v ${path to *.app} -o ${package path *.ipa}
- -v 你的
*.app
文件, 生成的*.xcarchive
里面有 - -o 打包生成的
*.ipa
文件路徑, 注意3谒怠G蛐簟费韭!這里是不能填相對(duì)路徑, 因?yàn)檫@里的路徑環(huán)境變量不是當(dāng)前執(zhí)行命令的路徑了
四. 最新的正確xcodebuild
導(dǎo)出ipa
xcodebuild -exportArchive -archivePath ${path to *.xcarchive} -exportPath ${export path to dir} -exportOptionsPlist ${path to export options *.plist}
- -archivePath 你的
*.xcarchive
文件, 可以使用第二個(gè)命令導(dǎo)出 - -exportPath 導(dǎo)出的
ipa
目錄, ipa的名稱好像是scheme的名稱 - -exportOptionsPlist 導(dǎo)出plist格式的配置文件
exportOptionPlist: 新建一個(gè)plist文件, 里面是一個(gè)Dictionary, key-value如下, 都是可選值, 不需要全部填上
- 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.
踩坑
坑一
使用第一個(gè)命令前, 需要確保你的項(xiàng)目的簽名配置好, 證書下好最新的
坑二
第二個(gè)命令的-exportProvisioningProfile
填的只是你的發(fā)布證書的名稱, 不是那一串id
坑三
第二個(gè)命令打包出來(lái)的*.ipa
不能用來(lái)上傳到AppStore
, 一直報(bào)CocoaPods里面的第三方庫(kù)簽名錯(cuò)誤
坑四
打包出來(lái)的*.ipa
需要上傳到AppSotre
的話, 可以使用第三個(gè)命令, xcrun
那一個(gè)
坑五
使用第三個(gè)命令打包出來(lái)的*.ipa
, 上傳到AppStore
之后, 登錄到iTunes Connect-APP-所有構(gòu)建版本
查看到上傳的*.ipa
正在構(gòu)建上炎。但是過(guò)了一會(huì)兒, AppleDeveloper
賬號(hào)的郵箱就會(huì)收到一封報(bào)錯(cuò)的郵件, 大概是說(shuō)你的*.ipa
包里面, 缺少了一個(gè)SwiftSupport
文件夾
經(jīng)過(guò)各種搜索之后, 原來(lái)需要把xcrun
打包出來(lái)的*.ipa
解壓, 然后新建一個(gè)文件夾, *.xcarchive
里面的SwiftSupport
文件夾copy
進(jìn)去, 還有把ipa
解壓出來(lái)的move
進(jìn)入, 最后打個(gè)zip包, 再改成ipa
后綴就可以上傳到AppStore
了(應(yīng)該吧, 還沒測(cè)試??)
坑六
經(jīng)過(guò)一輪測(cè)試之后, 發(fā)現(xiàn)用這個(gè)xcrun
這個(gè)命令打的包需要自己吧SwiftSupport文件加到壓縮包, 其實(shí)有一個(gè)命令沒有那么麻煩的...
使用上面的第四個(gè)命令使用*.xcarchive
把ipa導(dǎo)出, 導(dǎo)出的*.ipa
里面會(huì)包含了SwiftSupport
, 還不需要自己把它加進(jìn)去
番外篇
在踩到了第五個(gè)坑之后, 在github
發(fā)現(xiàn)了一個(gè)iOS
的打包谨读、發(fā)布庫(kù)...
上地址: https://github.com/nomad/shenzhen
懶得自己搞的可以使用這個(gè)庫(kù), 感覺還是挺不錯(cuò)的
Python封裝打包命令
github: package-ipa