配置 fastlane 框架自動化打包發(fā)布 iOS 應(yīng)用

fastlane/fastlane

安裝RVM

curl -sSL https://get.rvm.io | bash -s stable --ruby

安裝 RVM 是需要管理多版本的 Ruby 環(huán)境

安裝fastlane

gem install fastlane --verbose

fastlane初始化

在項目目錄下運(yùn)行

fastlane init

命令運(yùn)行時需要輸入Apple ID, 運(yùn)行成功后會生成 fastlane/Fastlane 文件, Fastlane 是一個 ruby 腳本

使用 bundler 管理依賴

官網(wǎng)介紹
bundler 用來管理 fastlane 自身版本和 fastlane 運(yùn)行時的相關(guān)依賴版本, 相當(dāng)于 iOS 開發(fā)中的 CocoaPods 框架, 使用方法也和 CocoaPods 如出一轍

  • 安裝 bundler
sudo gem install bundler
  • 在項目根目錄下新建 Gemfile 文件并寫入

    source "https://gems.ruby-china.org"
    
    gem "fastlane"
    gem "cocoapods"
    
  • 安裝依賴庫, 生成 Gemfile.lock 文件, 這個文件和我們平常接觸的 Podfile.lock 文件功能一致, 配置 CI 時也需要在每次構(gòu)建前調(diào)用該命令

    [sudo] bundle install
    
  • 更新 Gemfile.lock 文件

[sudo] bundle update
  • 運(yùn)行 fastlane 框架
bundle exec fastlane [lane]

安裝match

github官網(wǎng)介紹
match 是 fastlane 的一個功能組件, 采取了集中化方式來管理證書和 profile, 新建一個私有遠(yuǎn)程 git 庫用來保存證書和 profile, 一個 team 的開發(fā)者共用同一套證書, 方便了管理和配置, 同時 match 在證書過期時還會自動從蘋果官網(wǎng)下載新的證書并 push 到私有的 git 庫中, 保證證書同步, 不得不為這個想法點(diǎn)贊!

gem install match
xcode-select --install

match初始化

match init

命令運(yùn)行時需要輸入新建的用來保存證書的git地址, 運(yùn)行成功后會生成 Matchfile 配置文件

.
└── fastlane
    ├── Appfile
    ├── Fastfile
    ├── Matchfile
    └── README.md

接著運(yùn)行下面的兩條命令來生成證書和 profile

match appstore
match development

命令運(yùn)行時需要輸入Apple ID 和 密碼, 該密碼保存在系統(tǒng)的 keychain 中

如果不希望用 match 重新生成證書和 profile, 可以參考Micha? Laskowski的博客

如果當(dāng)前項目的證書和 profile 比較混亂, 可以用一下兩個命令來清空 Apple 官網(wǎng)上當(dāng)前全部證書和 profile 文件

match nuke development
match nuke distribution

match 擴(kuò)展

如果 Team 來了新成員, 在 clone 了項目工程后運(yùn)行下面的命令后, match 就從私有證書庫中下載develop 證書和 profile, 并安裝到新機(jī)上, 新成員就可以調(diào)試代碼了

match development --readonly

Jenkins 配置

jekins.png

遇到的問題

  • 運(yùn)行 match appstore 時遇到 openssl 庫版本問題, 更新 openssl 庫
AfluyFileSystem:Remote afluy$ match appstore
[19:53:01]: Successfully loaded '/Users/afluy/WorkCodeIOS/Remote/fastlane/Matchfile' ??
....
[19:53:01]: Cloning remote git repo...
/Library/Ruby/Gems/2.0.0/gems/fastlane_core-0.53.0/lib/fastlane_core/command_executor.rb:46: warning: Insecure world writable dir /Users/afluy/Applications/dex2jar-2.0 in PATH, mode 040777
[19:53:02]: ??  Successfully decrypted certificates repo
[19:53:02]: Verifying that the certificate and profile are still valid on the Dev Portal...
[19:53:20]: ??  Successfully encrypted certificates repo
[19:53:20]: -----------------------------------------------------------------------
[19:53:20]: Connection reset by peer - SSL_connect
[19:53:20]:
[19:53:20]: SSL errors can be caused by various components on your local machine.
[19:53:20]: Apple has recently changed their servers to require TLS 1.2, which may
[19:53:20]: not be available to your system installed Ruby (2.0.0)
[19:53:20]:
[19:53:20]: The best solution is to install a new version of Ruby
[19:53:20]:
[19:53:20]: - Make sure OpenSSL is installed with Homebrew: `brew update && brew upgrade openssl`
[19:53:20]: - If you use system Ruby:
[19:53:20]:   - Run `brew update && brew install ruby`
[19:53:20]: - If you use rbenv with ruby-build:
[19:53:20]:   - Run `brew update && brew upgrade ruby-build && rbenv install ruby-2.3.1`
[19:53:20]:   - Run `rbenv global ruby-2.3.1` to make it the new global default Ruby version
[19:53:20]: - If you use rvm:
[19:53:20]:   - First run `rvm osx-ssl-certs update all`
[19:53:20]:   - Then run `rvm reinstall ruby-2.3.1 --with-openssl-dir=/usr/local
[19:53:20]:
[19:53:20]: If that doesn't fix your issue, please google for the following error message:
[19:53:20]:   'Connection reset by peer - SSL_connect'
[19:53:20]: -----------------------------------------------------------------------

[!] Connection reset by peer - SSL_connect
  • 運(yùn)行 match development 時遇到 Apple 賬號權(quán)限問題, 請使用可以上傳 profile 的賬號
AfluyFileSystem:Remote afluy$ match development
[20:35:02]: Successfully loaded '/Users/afluy/WorkCodeIOS/Remote/fastlane/Matchfile' ??
...
[20:35:02]: Cloning remote git repo...
[20:35:03]: ??  Successfully decrypted certificates repo
[20:35:03]: Verifying that the certificate and profile are still valid on the Dev Portal...
[20:35:17]: Couldn't find a valid code signing identity in the git repo for development... creating one for you now
...
[20:35:17]: Starting login with user 'zhao.xianhua@whaley.cn'
[20:35:22]: Successfully logged in
[20:35:25]: $ security import /var/folders/_n/kyvgh8495bv5zmmdg7f85_1r0000gn/T/d20161027-57678-otquli/certs/development/K2935G9MQS.p12 -k '/Users/afluy/Library/Keychains/login.keychain' -T /usr/bin/codesign -T /usr/bin/security
[20:35:25]: ? 1 key imported.
[20:35:25]: $ security import /var/folders/_n/kyvgh8495bv5zmmdg7f85_1r0000gn/T/d20161027-57678-otquli/certs/development/K2935G9MQS.cer -k '/Users/afluy/Library/Keychains/login.keychain' -T /usr/bin/codesign -T /usr/bin/security
[20:35:25]: ? 1 certificate imported.
[20:35:25]: Successfully generated K2935G9MQS which was imported to the local machine.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1062  100  1062    0     0    825      0  0:00:01  0:00:01 --:--:--   825
[20:35:28]: Verifying the certificate is properly installed locally...
[20:35:28]: Successfully installed certificate K2935G9MQS

...

[20:35:29]: Starting login with user '...'
[20:35:31]: Successfully logged in
[20:35:31]: Fetching profiles...
[20:35:31]: No existing profiles found, that match the certificates you have installed locally! Creating a new provisioning profile for you
[20:35:35]: Creating new provisioning profile for '...' with name 'match Development ...'
[20:35:38]: An error occured while verifying your certificates and profiles with the Apple Developer Portal.
[20:35:38]: If you already have your certificates stored in git, you can run `match` in readonly mode
[20:35:38]: to just install the certificates and profiles without accessing the Dev Portal.
[20:35:38]: To do so, just pass `readonly: true` to your match call.
[20:35:38]: ??  Successfully encrypted certificates repo

Looking for related GitHub issues on fastlane/fastlane...

Found no similar issues. To create a new issue, please visit:
https://github.com/fastlane/fastlane/issues/new

[!] Apple provided the following error info:
    You are not permitted to create provisioning profiles for team.  Please contact one of your team admins, who can create a profile on your behalf.
  • Apple 官網(wǎng)和本地機(jī)器上已經(jīng)有證書, 需要刪除官網(wǎng)和本地的證書, 也可以運(yùn)行上面說的 match nuke 命令來清空已有的證書
AfluyFileSystem:Remote afluy$ match development
[10:53:48]: Successfully loaded '/Users/afluy/WorkCodeIOS/Remote/fastlane/Matchfile' ??
...
[10:53:48]: Cloning remote git repo...
[10:53:54]: ??  Successfully decrypted certificates repo
[10:53:54]: Verifying that the certificate and profile are still valid on the Dev Portal...
[10:54:00]: Couldn't find a valid code signing identity in the git repo for development... creating one for you now
...
[10:54:00]: Starting login with user 'zhao.xianhua@whaley.cn'
[10:54:02]: Successfully logged in
[10:54:05]: ??  Successfully encrypted certificates repo

Looking for related GitHub issues on fastlane/fastlane...

??  match: Could not create another certificate, reached the maximum number of available certificates.
   https://github.com/fastlane/fastlane/issues/5765 [closed] 4 ??
   17 Aug 2016

??  Could not create another certificate, reached the maximum number of available certificates.
   https://github.com/fastlane/fastlane/issues/3472 [closed] 9 ??
   5 weeks ago

??  Could not create another certificate, reached the maximum number of available certificates
   https://github.com/fastlane/fastlane/issues/3123 [closed] 10 ??
   5 weeks ago

and 10 more at: https://github.com/fastlane/fastlane/search?q=Could%20not%20create%20another%20Development%20certificate,%20reached%20the%20maximum%20number%20of%20available%20Development%20certificates.&type=Issues&utf8=?

[!] Could not create another Development certificate, reached the maximum number of available Development certificates.
  • Team 中其他開發(fā)者需要在 Xcode 中選擇 Automatically manage signing
  • 在 Setting up CocoaPods master repo 卡住, 這個是 CocoaPods 需要全部 clone 下來, 我最終下載了大概 700M 的文件~~
  • 如果不能將改動提交到私有的存儲證書的遠(yuǎn)程 git 庫, 可以檢查該 git 庫的master分支是否被保護(hù)

參考資料

https://codesigning.guide/
https://github.com/fastlane/fastlane
https://icyleaf.com/2016/07/intro-fastlane-automation-for-ios-and-android/
https://rvm.io/rvm/install
https://ruby-china.org/wiki/rvm-guide
https://ruby-china.org/wiki/install_ruby_guide
http://macoscope.com/blog/simplify-your-life-with-fastlane-match/#main
http://stackoverflow.com/questions/36963467/how-do-i-manually-add-existing-provisioning-profiles-and-certificates-to-fastlan
http://macoscope.com/blog/simplify-your-life-with-fastlane-match/#migration

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末景馁,一起剝皮案震驚了整個濱河市胳螟,隨后出現(xiàn)的幾起案子嚼摩,更是在濱河造成了極大的恐慌双泪,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,214評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件居凶,死亡現(xiàn)場離奇詭異界逛,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)瞧筛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評論 2 382
  • 文/潘曉璐 我一進(jìn)店門厉熟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人较幌,你說我怎么就攤上這事揍瑟。” “怎么了乍炉?”我有些...
    開封第一講書人閱讀 152,543評論 0 341
  • 文/不壞的土叔 我叫張陵绢片,是天一觀的道長。 經(jīng)常有香客問我岛琼,道長底循,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,221評論 1 279
  • 正文 為了忘掉前任槐瑞,我火速辦了婚禮熙涤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘困檩。我一直安慰自己祠挫,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評論 5 371
  • 文/花漫 我一把揭開白布悼沿。 她就那樣靜靜地躺著等舔,像睡著了一般。 火紅的嫁衣襯著肌膚如雪糟趾。 梳的紋絲不亂的頭發(fā)上慌植,一...
    開封第一講書人閱讀 49,007評論 1 284
  • 那天,我揣著相機(jī)與錄音拉讯,去河邊找鬼涤浇。 笑死,一個胖子當(dāng)著我的面吹牛魔慷,可吹牛的內(nèi)容都是我干的只锭。 我是一名探鬼主播,決...
    沈念sama閱讀 38,313評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼院尔,長吁一口氣:“原來是場噩夢啊……” “哼蜻展!你這毒婦竟也來了喉誊?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,956評論 0 259
  • 序言:老撾萬榮一對情侶失蹤纵顾,失蹤者是張志新(化名)和其女友劉穎伍茄,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體施逾,經(jīng)...
    沈念sama閱讀 43,441評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡敷矫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了汉额。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片曹仗。...
    茶點(diǎn)故事閱讀 38,018評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖蠕搜,靈堂內(nèi)的尸體忽然破棺而出怎茫,到底是詐尸還是另有隱情,我是刑警寧澤妓灌,帶...
    沈念sama閱讀 33,685評論 4 322
  • 正文 年R本政府宣布轨蛤,位于F島的核電站,受9級特大地震影響虫埂,放射性物質(zhì)發(fā)生泄漏祥山。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評論 3 307
  • 文/蒙蒙 一告丢、第九天 我趴在偏房一處隱蔽的房頂上張望枪蘑。 院中可真熱鬧,春花似錦岖免、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至栗精,卻和暖如春闯参,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背悲立。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評論 1 261
  • 我被黑心中介騙來泰國打工鹿寨, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人薪夕。 一個月前我還...
    沈念sama閱讀 45,467評論 2 352
  • 正文 我出身青樓脚草,卻偏偏與公主長得像,于是被迫代替她去往敵國和親原献。 傳聞我的和親對象是個殘疾皇子馏慨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評論 2 345

推薦閱讀更多精彩內(nèi)容