【工具】使用Fastlane实现iOS项目自动打包上传到App Store和第三方托管蒲公英平台

一、安装前准备

开发环境:


1.OS X 10.9 (Mavericks) 以上
2.Ruby 2.0 以上
3.Xcode 最新版
4.拥有一个付费的苹果开发者账号(我的账号是加入开发组,并且给我开了管理员权限,未付费)

二、配置环境

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

# 安装
curl -L get.rvm.io | bash -s stable  
  
# 测试是否安装正常
rvm -v

# 列出已知ruby版本         
rvm list known   

# 安装一个最新ruby版本 注:此处xxxxx为list中的最新版本号    
rvm install ruby-xxxxx     

# 如果报错的话
brew install openssl 

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

以上所需的ruby环境基本配置好了

3、打开终端,选择ruby 源
(rubygems、taobao这两个源不知道哪个能成功,所以都分别切换试一下,后文会提到)

# 查看gem源
gem sources

# 删除默认的gem源
gem sources --remove https://rubygems.org/

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

# 查看当前的gem源
gem sources
*** CURRENT SOURCES ***
http://ruby.taobao.org

# 清空源缓存
gem sources -c

# 更新源缓存
gem sources -u

三、安装Fastlane

1、安装xcode-select
xcode-select --install

# 如果 Xcode CLT 已经安装,则会报如下错误
# command line tools are already installed, use "Software Update" to install updates.
# 如果未安装,终端会开始安装 CLT

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

#  如果报错:ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/commander 
sudo gem install -n /usr/local/bin fastlane 

# 等待着安装完毕....coffee or tea

# 安装结束后,查看版本
fastlane --version

# 实际上目前安装的fastlane并不是最新版本,还需要更新,怎么更新呢,看下面

# cd到项目文件夹
cd xxxxx

# 初始化文件
fastlane init

Fastlane版本号


Fastlane在项目文件夹初始化后产生的文件


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


五、使用

切换到项目根目录下
1、上传到App Store
fastlane ldd_release

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容