Fastlane:入门与实战


Fastlane Github地址
Fastlane Tools

1. Fastlane简介:

The easiest way to automate building and releasing your iOS and Android apps.

Fastlane 化繁为简,只需一条命令就可实现从 Xcode 项目到 编译\打包\构建\提交审核。

2. Fastlane 安装

官网安装教程直达链接
首先,确保你已经安装了最新的 Xcode command line tools

xcode-select --install

由于 masOS 新的文件权限限制,如果在网上搜到的安装命令不成功,尝试添加-n /usr/local/bin

$ sudo gem install -n /usr/local/bin fastlane
Password:
Successfully installed fastlane-2.35.1
Parsing documentation for fastlane-2.35.1
Done installing documentation for fastlane after 10 seconds
1 gem installed

检查 Fastlane 版本

➜  ~ fastlane --version
fastlane installation at path:
/usr/local/Cellar/ruby/2.4.1/lib/ruby/gems/2.4.0/gems/fastlane-2.35.1/bin/fastlane
-----------------------------
fastlane 2.35.1

安装成功

3. 开始使用 Fastlane

在终端中 cd 到你的工程的根目录,然后输入命令

fastlane init

如果是第一次使用 fastlane ,会要求输入你的苹果开发者账号

cd 项目目录
fastlane init 
[17:29:05]: Your Apple ID (e.g. fastlane@krausefx.com): 你的开发者AppleID
[17:29:40]: Verifying that app is available on the Apple Developer Portal and iTunes Connect...
[17:29:40]: Starting login with user 'xxxxx'

+----------------+--------------------------------------+
|                    Detected Values                    |
+----------------+--------------------------------------+
| Apple ID       |        xxxx               |
| App Name       |             xxxx                    |
| App Identifier |           xxxxx            |
| Workspace      |        xxxxx          |
+----------------+--------------------------------------+

[17:29:52]: Please confirm the above values (y/n)
...
// init 成功
[17:31:26]: Successfully finished setting up fastlane
//如果已经 init 过,就是下面的内容
[17:24:56]: fastlane is already set up at path ./fastlane/
  • 期间会让你输入 Apple ID 账号密码(这个信息会存在钥匙串中,后续使用无需再输入密码)
  • 会检测当前的 app identifier 是否在 Apple Dev Center 中
  • 会检测当前 app 是否在 iTunes Connect 中
  • 如果已经在 Apple Dev Center 和 iTunes Connect 中创建相应的信息,那么过程会很顺利

成功之后,会在你工程的根目录下创建fastlane文件夹,里面都是从 iTunes Connect 获取到的当前 App 的相关信息。
你最感兴趣的文件应该是fastlane/Fastfile,因为它包含了你分发你的 APP 的所有信息。

3.1 使用 fastlane 部署 iOS 测试
3.1.2 打包 APP

通过 fastlane 的工具 gym 实现自动打包,修改之前提到的文件fastlane/Fastfile,添加以下内容

lane :beta do
  gym(scheme: "MyApp")
end

另外,你也可以添加一些打包选项,如:

lane :beta do
  gym(scheme: "MyApp",
      workspace: "Example.xcworkspace",
      include_bitcode: true)
end

通过运行下面的命令执行上面的lane,实现自动打包

fastlane beta

如果一切 OK,会在当前目录下创建[ProductName].ipa

了解更多gym用法,通过命令

fastlane action gym

或者访问官网 fastlane/gym

3.1.2 使用 Fastlane 上传 App 到蒲公英

官网有一篇教程,可是我按照这个教程没有成功过,Google 了大半天还是没搞定,就在从入门到放弃的时候,看到了蒲公英在 Github 上的介绍,终于解决了问题。我的解决办法如下:

  • 首先在终端中cd到你的Project根目录,然后通过以下命令为你的Project安装蒲公英Fastlane插件
fastlane add_plugin pgyer
[11:13:24]: Make sure to commit your Gemfile, Gemfile.lock and Pluginfile to version control
Installing plugin dependencies...
Successfully installed plugins
  • 成功后就可以修改Fastlane文件,关键代码如下:
default_platform :ios

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

desc " lane 描述信息:通过蒲公英 fastlane 插件实现上传 APP 到蒲公英"
 lane :beta do
   gym(scheme:"xxx",
       workspace: "xxx.xcworkspace",
       export_method: "ad-hoc")
   pgyer(api_key: "从蒲公英项目详情中获取的 apikey",
         user_key: "从蒲公英项目详情中获取的 userkey",
         update_description: "本次测试更新的文字说明")
 end
  • 最后,运行下面命令,实现自动打包上传 APP 到蒲公英。
fastlane beta
  • 成功的信息如下
[11:23:58]: Successfully exported and compressed dSYM file
# 成功打包
[11:23:58]: Successfully exported and signed the ipa file:
[11:23:58]: /Users/xxxx/Documents/ComponyProject/xxx/xxx/trunk/xxx/xxx.ipa
[11:23:58]: -------------------
[11:23:58]: --- Step: pgyer ---
[11:23:58]: -------------------
[11:23:58]: The pgyer plugin is working.
[11:23:58]: build_file: /Users/xxx/Documents/ComponyProject/xxx/xxxx/trunk/xxxx/xxx.ipa
[11:23:58]: Start upload /Users/xxx/Documents/ComponyProject/xxx/xxx/trunk/xxx/xxx.ipa to pgyer...
# 成功上传到蒲公英,打开下载连接查看
[11:24:02]: Upload success. Visit this URL to see: https://www.pgyer.com/xxxx

+------+---------------------+-------------+
|             fastlane summary             |
+------+---------------------+-------------+
| Step | Action              | Time (in s) |
+------+---------------------+-------------+
| 1    | Verifying required  | 0           |
|      | fastlane version    |             |
| 2    | default_platform    | 0           |
| 3    | cocoapods           | 4           |
| 4    | gym                 | 148         |
| 5    | pgyer               | 4           |
+------+---------------------+-------------+

[11:24:02]: fastlane.tools finished successfully 🎉

总结:

  • 自己犯得第一个错误是没有安装蒲公英插件到当前工程,而是直接在终端中输入了fastlane add_plugin pgyer,以为这个插件是全局的。官方的文档也没有很明确的说出这一点,难道是这个git:(master)?

GitHub 倒是很明确的说明了

This project is a fastlane plugin. To get started with fastlane-plugin-pgyer
, add it to your project by running:

fastlane add_plugin pgyer
  • 官网教程是通过bundle实现的。但是通过命令bundle exec老是卡死在 cocoapods 上,Google 了半天也没解决(自己对 Ruby 不熟悉,GemfileGemfile.lock添加了gem 'cocoapods',gem 'fastlane'还是无效,懒得深入了)
    Fastlane failed to run pod install
    解决方法是:在 Fastlane 文件修改如下:
before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    # 如果是 cocoapods 尝试改为下面内容
    cocoapods(use_bundle_exec: false)
    
  end
  • 蒲公英的进阶用法请参考官网,比如加密发布。

参考:

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