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

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

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


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

二辜梳、配置環(huán)境

1撬讽、安裝xcode
2铲觉、更新ruby版本窝稿,安裝rvm

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

# 列出已知ruby版本         
rvm list known   

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

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

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

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

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

# 查看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)安裝卧斟,則會報(bào)如下錯(cuò)誤
# command line tools are already installed, use "Software Update" to install updates.
# 如果未安裝殴边,終端會開始安裝 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版本號


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版本號
    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)容合作請聯(lián)系作者
  • 序言:七十年代末亡驰,一起剝皮案震驚了整個(gè)濱河市晓猛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌凡辱,老刑警劉巖戒职,帶你破解...
    沈念sama閱讀 216,843評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異透乾,居然都是意外死亡洪燥,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評論 3 392
  • 文/潘曉璐 我一進(jìn)店門乳乌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來捧韵,“玉大人,你說我怎么就攤上這事汉操≡倮矗” “怎么了?”我有些...
    開封第一講書人閱讀 163,187評論 0 353
  • 文/不壞的土叔 我叫張陵磷瘤,是天一觀的道長芒篷。 經(jīng)常有香客問我,道長采缚,這世上最難降的妖魔是什么针炉? 我笑而不...
    開封第一講書人閱讀 58,264評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮扳抽,結(jié)果婚禮上糊识,老公的妹妹穿的比我還像新娘绩社。我一直安慰自己,他們只是感情好赂苗,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,289評論 6 390
  • 文/花漫 我一把揭開白布愉耙。 她就那樣靜靜地躺著,像睡著了一般拌滋。 火紅的嫁衣襯著肌膚如雪朴沿。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,231評論 1 299
  • 那天败砂,我揣著相機(jī)與錄音赌渣,去河邊找鬼。 笑死昌犹,一個(gè)胖子當(dāng)著我的面吹牛坚芜,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播斜姥,決...
    沈念sama閱讀 40,116評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼鸿竖,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了铸敏?” 一聲冷哼從身側(cè)響起缚忧,我...
    開封第一講書人閱讀 38,945評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎杈笔,沒想到半個(gè)月后闪水,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,367評論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蒙具,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,581評論 2 333
  • 正文 我和宋清朗相戀三年球榆,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片禁筏。...
    茶點(diǎn)故事閱讀 39,754評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡芜果,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出融师,到底是詐尸還是另有隱情,我是刑警寧澤蚁吝,帶...
    沈念sama閱讀 35,458評論 5 344
  • 正文 年R本政府宣布旱爆,位于F島的核電站,受9級特大地震影響窘茁,放射性物質(zhì)發(fā)生泄漏怀伦。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,068評論 3 327
  • 文/蒙蒙 一山林、第九天 我趴在偏房一處隱蔽的房頂上張望房待。 院中可真熱鬧,春花似錦、人聲如沸桑孩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,692評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽流椒。三九已至敏簿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間宣虾,已是汗流浹背惯裕。 一陣腳步聲響...
    開封第一講書人閱讀 32,842評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留绣硝,地道東北人蜻势。 一個(gè)月前我還...
    沈念sama閱讀 47,797評論 2 369
  • 正文 我出身青樓,卻偏偏與公主長得像鹉胖,于是被迫代替她去往敵國和親握玛。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,654評論 2 354

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