【工具】使用Fastlane實(shí)現(xiàn)iOS項(xiàng)目自動(dòng)打包上傳到App Store和第三方托管蒲公英平臺(tái)

一、安裝前準(zhǔn)備

開發(fā)環(huán)境:


1.OS X 10.9 (Mavericks) 以上
2.Ruby 2.0 以上
3.Xcode 最新版
4.擁有一個(gè)付費(fèi)的蘋果開發(fā)者賬號(hào)(我的賬號(hào)是加入開發(fā)組,并且給我開了管理員權(quán)限,未付費(fèi))

二、配置環(huán)境

1、安裝xcode
2、更新ruby版本,安裝rvm

# 安裝
curl -L get.rvm.io | bash -s stable  
  
# 測(cè)試是否安裝正常
rvm -v

# 列出已知ruby版本         
rvm list known   

# 安裝一個(gè)最新ruby版本 注:此處xxxxx為list中的最新版本號(hào)    
rvm install ruby-xxxxx     

# 如果報(bào)錯(cuò)的話
brew install openssl 

# 注意修改xxxxxx
reinstall|install ruby-xxxxx     

以上所需的ruby環(huán)境基本配置好了

3、打開終端,選擇ruby 源
(rubygems、taobao這兩個(gè)源不知道哪個(gè)能成功,所以都分別切換試一下,后文會(huì)提到)

# 查看gem源
gem sources

# 刪除默認(rèn)的gem源
gem sources --remove https://rubygems.org/

# 增加taobao作為gem源
gem sources -a https://ruby.taobao.org/

# 查看當(dāng)前的gem源
gem sources
*** CURRENT SOURCES ***
http://ruby.taobao.org

# 清空源緩存
gem sources -c

# 更新源緩存
gem sources -u

三、安裝Fastlane

1、安裝xcode-select
xcode-select --install

# 如果 Xcode CLT 已經(jīng)安裝,則會(huì)報(bào)如下錯(cuò)誤
# command line tools are already installed, use "Software Update" to install updates.
# 如果未安裝,終端會(huì)開始安裝 CLT

2.安裝fastlane
sudo gem install fastlane --verbose

#  如果報(bào)錯(cuò):ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/commander 
sudo gem install -n /usr/local/bin fastlane 

# 等待著安裝完畢....coffee or tea

# 安裝結(jié)束后,查看版本
fastlane --version

# 實(shí)際上目前安裝的fastlane并不是最新版本,還需要更新,怎么更新呢,看下面

# cd到項(xiàng)目文件夾
cd xxxxx

# 初始化文件
fastlane init

Fastlane版本號(hào)


Fastlane在項(xiàng)目文件夾初始化后產(chǎn)生的文件


Snip20170608_8.png

四、配置文件修改

# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.37.0"

default_platform :ios

platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    #cocoapods
    
  end

  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    gym(scheme: "FM") # Build your app - more options available
    pilot

    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  desc "Deploy a new version to the App Store"
  lane :release do
    # match(type: "appstore")
    # snapshot
    gym(scheme: "FM") # Build your app - more options available
    deliver(force: true)
    # frameit
  end

#2.定義自定義lane 上傳到App Store
  desc "自定義lane"
  lane :ldd_release do
  #2.1編譯 選擇scheme和功能
    # 增加build版本號(hào)
    increment_build_number
    gym(
      scheme: "FM",
      workspace: "com.xxxx.xxxxx",
      include_bitcode: false
      )

    deliver(
    #2.2上傳appstore
      force: true,
      # skip_metadata: true,
      skip_screenshots: true,
      # skip uploading an ipa or pkg to iTunes  如果有最新包ipa包上傳一定要 fasle
      skip_binary_upload: false,
      submit_for_review: true,
      automatic_release: true,
      price_tier: 0
      ) 
  end

# 上傳到蒲公英
  lane :ldd_beta do
     gym(
        export_method: "ad-hoc",
        scheme: "FM"
        )
  pgyer(api_key: "accxxxxxxxxxb731b1c", user_key: "4f223xxxxxxxxxxxc089bb7e")
  end

  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://docs.fastlane.tools/actions

# fastlane reports which actions are used. No personal data is recorded. 
# Learn more at https://github.com/fastlane/fastlane#metrics


五、使用

切換到項(xiàng)目根目錄下
1、上傳到App Store
fastlane ldd_release

2、上傳到蒲公英
bundle exec fastlane ldd_beta

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,327評(píng)論 6 537
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,996評(píng)論 3 423
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,316評(píng)論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,406評(píng)論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 72,128評(píng)論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,524評(píng)論 1 324
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,576評(píng)論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,759評(píng)論 0 289
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,310評(píng)論 1 335
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 41,065評(píng)論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 43,249評(píng)論 1 371
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,821評(píng)論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,479評(píng)論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,909評(píng)論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,140評(píng)論 1 290
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 51,984評(píng)論 3 395
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 48,228評(píng)論 2 375

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