iOS Fastlane 使用文档


更新时间:2019-4-8

一、开始使用前的准备工作检查环境配置:

1、检查ruby

命令:ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

如果没有安装请,移步这里

2、Xcode命令工具

命令:xcode-select -v
xcode-select version 2354.
如果没有安装,就安装命令:xcode-select --install

3、安装fastlane

sudo gem install fastlane --verbose

如果安装失败:

ERROR:  While executing gem ... (TypeError)
    no implicit conversion of nil into String

进行更新gem:

sudo gem update --system

安装成功:

➜  1.0 fastlane -v
Ignoring bigdecimal-1.3.5 because its extensions are not built.  Try: gem pristine bigdecimal --version 1.3.5
fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.112.0/bin/fastlane
-----------------------------
[⠹] 🚀 Ignoring io-console-0.4.6 because its extensions are not built.  Try: gem pristine io-console --version 0.4.6
Ignoring nokogiri-1.8.4 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.4
Ignoring psych-3.0.2 because its extensions are not built.  Try: gem pristine psych --version 3.0.2
Ignoring sqlite3-1.3.13 because its extensions are not built.  Try: gem pristine sqlite3 --version 1.3.13
[✔] 🚀 
fastlane 2.112.0

二、项目初始化

fastlane init

出现如下信息:

[15:08:29]: What would you like to use fastlane for?
1. 📸  Automate screenshots
2. 👩‍✈️  Automate beta distribution to TestFlight
3. 🚀  Automate App Store distribution
4. 🛠  Manual setup - manually setup your project to automate your tasks
?  

翻译:
1. 自动截屏。这个功能能帮我们自动截取APP中的截图,并添加手机边框(如果需要的话),我们这里不选择这个选项,因为我们的项目已经有图片了,不需要这里截屏。
2. 自动发布beta版本用于TestFlight,如果大家有对TestFlight不了解的,可以参考王巍写的这篇文章
3. 自动的App Store发布包。我们的目标是要提交审核到APP Store,按道理应该选这个,但这里我们先不选,因为选择了以后会需要输入用户名密码,以及下载meta信息,需要花费一定时间,这些数据我们可以后期进行配置。
4. 手动设置。

直接选择第4个对其进行手动配置后进入:

[15:17:15]: ------------------------------------------------------------
[15:17:15]: --- Setting up fastlane so you can manually configure it ---
[15:17:15]: ------------------------------------------------------------
[15:17:15]: Installing dependencies for you...
[15:17:15]: $ bundle update

等待时间较长.....
安装成功如下:

➜  1.0 fastlane init
Ignoring bigdecimal-1.3.5 because its extensions are not built.  Try: gem pristine bigdecimal --version 1.3.5
[⠹] 🚀 Ignoring io-console-0.4.6 because its extensions are not built.  Try: gem pristine io-console --version 0.4.6
Ignoring nokogiri-1.8.4 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.4
Ignoring psych-3.0.2 because its extensions are not built.  Try: gem pristine psych --version 3.0.2
Ignoring sqlite3-1.3.13 because its extensions are not built.  Try: gem pristine sqlite3 --version 1.3.13
[✔] 🚀 
[15:37:31]: ------------------------------
[15:37:31]: --- Step: default_platform ---
[15:37:31]: ------------------------------

--------- ios---------
----- fastlane ios custom_lane
Description of what the lane does

Execute using `fastlane [lane_name]`
[15:37:31]: ------------------
[15:37:31]: fastlane is already set up at path `./fastlane/`, see the available lanes above
[15:37:31]: 
[15:37:31]: ------------------------------
[15:37:31]: --- Where to go from here? ---
[15:37:31]: ------------------------------
[15:37:31]: 📸  Learn more about how to automatically generate localized App Store screenshots:
[15:37:31]:         https://docs.fastlane.tools/getting-started/ios/screenshots/
[15:37:31]: 👩‍✈️  Learn more about distribution to beta testing services:
[15:37:31]:         https://docs.fastlane.tools/getting-started/ios/beta-deployment/
[15:37:31]: 🚀  Learn more about how to automate the App Store release process:
[15:37:31]:         https://docs.fastlane.tools/getting-started/ios/appstore-deployment/
[15:37:31]: 👩‍⚕️  Learn more about how to setup code signing with fastlane
[15:37:31]:         https://docs.fastlane.tools/codesigning/getting-started/
➜  1.0 

其他命令:

fastlane actions:      列出所有可用fastlane活动
fastlane action [action_name]:   显示一个更详细的活动描述
fastlane lanes:      列出所有可用lanes (有描述)
fastlane list:       列出所有可用lanes (没有描述)
fastlane new_action:     在fastlane创建一个活动(集成)

三、对fastlane 文件的认识:

现在对Appfile,Fastfile,Gemfile,Deliverfile文件说明如下:

Appfile: 存储有关开发者账号相关信息
Fastfile: 核心文件,用于命令行调用和处理具体的流程,lane相对于一个action方法或函数 
Gemfile 类似于cocopods 的Podfile文件
.env 配置环境变量(在fastlane init进行初始化后并不会自动生成,如果需要可以自己创建
Deliverfile: deliver工具的配置文件,上传截图苹果和后台一些app信息  (默认不生成,需要sudo gem install deliver安装)然后在fastlane 目录下执行deliver init 即可)
要注意的点:
build_app命令等同于gym(别名)
deliver 命令相当于upload_to_app_store(别名)

四、添加插件

列出所有的插件

fastlane search_plugins

搜索指定名称的插件

fastlane search_plugins [query]

添加插件

fastlane add_plugin [name]

安装插件

fastlane install_plugins

添加蒲公英插件
fastlane add_plugin pgyer
fastlane add_plugin versioning

添加match全家桶

fastlane match init

五、配置相关文件信息

配置主文件:Fastfile
配置证书的存放路径

fastlane ios
[16:42:53]: $ bundle exec fastlane ios
[16:42:53]: 
[16:42:53]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
+------------------------+---------+------------------------+
|                       Used plugins                        |
+------------------------+---------+------------------------+
| Plugin                 | Version | Action                 |
+------------------------+---------+------------------------+
| fastlane-plugin-pgyer  | 0.2.2   | pgyer                  |
| fastlane-plugin-versi  | 0.3.4   | get_version_number_fr  |
| oning                  |         | om_git_branch          |
|                        |         | get_version_number_fr  |
|                        |         | om_plist               |
|                        |         | get_build_number_from  |
|                        |         | _plist                 |
|                        |         | ci_build_number        |
|                        |         | increment_version_num  |
|                        |         | ber_in_plist           |
|                        |         | get_app_store_version  |
|                        |         | _number                |
|                        |         | get_info_plist_path    |
|                        |         | increment_build_numbe  |
|                        |         | r_in_plist             |
+------------------------+---------+------------------------+

[16:42:55]: ------------------------------
[16:42:55]: --- Step: default_platform ---
[16:42:55]: ------------------------------
[16:42:55]: Welcome to fastlane! Here's what your app is setup to do:
+--------+-----------------+----------------------+
|             Available lanes to run              |
+--------+-----------------+----------------------+
| Number | Lane Name       | Description          |
+--------+-----------------+----------------------+
| 1      | ios custom_lane | Description of what  |
|        |                 | the lane does        |
| 0      | cancel          | No selection, exit   |
|        |                 | fastlane!            |
+--------+-----------------+----------------------+
[16:42:55]: Which number would you like run?

六、遇到问题

出现错误:

[17:13:49]: ▸ ** ARCHIVE SUCCEEDED **
[17:13:49]: 
[17:13:49]: ⬆️  Check out the few lines of raw `xcodebuild` output above for potential hints on how to solve this error
[17:13:49]: 📋  For the complete and more detailed error log, check the full log at:
[17:13:49]: 📋  /Users/liujingxu/Library/Logs/gym/M-Pay-M-Pay.log
[17:13:49]: 
[17:13:49]: Looks like fastlane ran into a build/archive error with your project
[17:13:49]: It's hard to tell what's causing the error, so we wrote some guides on how
[17:13:49]: to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[17:13:49]: Before submitting an issue on GitHub, please follow the guide above and make
[17:13:49]: sure your project is set up correctly.
[17:13:49]: fastlane uses `xcodebuild` commands to generate your binary, you can see the
[17:13:49]: the full commands printed out in yellow in the above log.
[17:13:49]: Make sure to inspect the output above, as usually you'll find more error information there
[17:13:49]: 
[17:13:49]: Looks like no provisioning profile mapping was provided
[17:13:49]: Please check the complete output, in particular the very top
[17:13:49]: and see if you can find more information. You can also run fastlane
[17:13:49]: with the `--verbose` flag.
[17:13:49]: Alternatively you can provide the provisioning profile mapping manually
[17:13:49]: https://docs.fastlane.tools/codesigning/xcode-project/#xcode-9-and-up
+------------------+---------------+
|           Lane Context           |
+------------------+---------------+
| DEFAULT_PLATFORM | ios           |
| PLATFORM_NAME    | ios           |
| LANE_NAME        | ios adhoc_pgy |
| BUILD_NUMBER     | 2             |
+------------------+---------------+
[17:13:49]: Error packaging up the application

+------+------------------------+-------------+
|              fastlane summary               |
+------+------------------------+-------------+
| Step | Action                 | Time (in s) |
+------+------------------------+-------------+
| 1    | default_platform       | 0           |
| 2    | cocoapods              | 3           |
| 3    | increment_build_numbe  | 1           |
|      | r                      |             |
| 💥   | build_app              | 84          |
+------+------------------------+-------------+

[17:13:49]: fastlane finished with errors

[!] Error packaging up the application

match文件配置

  1. 首页需要一个git仓库用来存放Cer证书
  2. git 仓库需要添加ssh公钥
生产密钥:ssh-keygen 
查看密钥:cat ~/.ssh/id_rsa.pub

2、错误信息

[16:19:23]: URL to the git repo containing all the certificates: https://gitee.com/mxlj/M-Pay-Cer.git
[16:19:33]: Cloning remote git repo...
[16:19:33]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
Cloning into '/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2'...
fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
[16:19:34]: Exit status: 128
[16:19:34]: Error cloning certificates repo, please make sure you have read access to the repository you want to use
[16:19:34]: Run the following command manually to make sure you're properly authenticated:
[16:19:34]: $ git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2

[!] Error cloning certificates git repo, please make sure you have access to the repository - see instructions above

解决方法:

注:出现这个问题是因为mac git终端没有读写的权限,问题。
未找到修改权限的方法来解决此问题,所有使用下面的方面来解决。

运行:

git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/xc/bzrxbntn1fq_fw53ks0_jbzc0000gn/T/d20190409-13848-156jw68

提示输入git的账号:xxx@.com
提示输入git的密码:xxxx

这样就进行了git仓库的关联。

运行:fastlane match adhoc,需要输入app账号的密码

然后需要确认使用哪个组织来进行证书下载,在打包的时候也是。

还有一个git仓库的密码:123456,这个密码在其他的电脑上会使用到,会去仓库里下载证书.

问题:

Couldn't find specified scheme 'scheme'. Please make sure that the scheme is shared, see https://developer.apple.com/library/content/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/ConfigureBots.html#//apple_ref/doc/uid/TP40013292-CH9-SW3

修改Fastlane文件的scheme:为项目名称

报satus 70错误

** EXPORT FAILED **
[17:28:29]: Exit status: 70

解决办法:
把xcode证书自动管理修改为手段管理,就可以解决此问题。
至于具体原因未找到。

问题

[09:50:03]: Could not find action, lane or variable 'pgyer'. Check out the documentation for more details: https://docs.fastlane.tools/actions

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
| 2    | sigh             | 17          |
| 3    | gym              | 67          |
+------+------------------+-------------+

[09:50:03]: fastlane finished with errors

[!] Could not find action, lane or variable 'pgyer'. Check out the documentation for more details: https://docs.fastlane.tools/actions

解决:

是因为无法找到蒲公英的插件,脚本里加了,但是命令没有加。

fastlane add_plugin pgyer
//版本管理
fastlane add_plugin versioning


完成上传成功

iOS打包命令

ios test

fastlane ios test

ios release

fastlane ios release

ios appstore

fastlane ios appstore

其他注意事项

当已经创建好了主的fastlane的证书,其他电脑上只获取就可以了:

fastlane match development readonly

fastlane match adhoc readonly

添加新设备后更新证书
fastlane match development --force_for_new_devices

fastlane match adhoc --force_for_new_devices


rom the Apple Dev Portal
    nuke development    Delete all certificates and provisioning profiles
from the Apple Dev Portal of the type development
    nuke distribution   Delete all certificates and provisioning profiles
from the Apple Dev Portal of the type distribution
    nuke enterprise     Delete all certificates and provisioning profiles
from the Apple Dev Portal of the type enterprise
    run               * Easily sync your certificates and profiles across
your team

分割线


xcode 多config配置

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

推荐阅读更多精彩内容

  • fastlane运行所需要的环境: OS X 10.9以上 Ruby 2.0 以上 Xcode 拥有一个开发者账号...
    阿姣_0405阅读 2,936评论 0 4
  • 毋庸置疑,Jenkins对我们打包的帮助还是很大的——被测试的同学追着要IPA包的日子终于一去不复返了。但作为追求...
    iOS逆向开发阅读 1,534评论 2 10
  • 毋庸置疑,Jenkins对我们打包的帮助还是很大的——被测试的同学追着要IPA包的日子终于一去不复返了。但作为追求...
    _VisitorsZsl阅读 1,146评论 0 4
  • 前言:一直有听过脚本一键打包审核,但是自己一直没在意。在微信公众号看到ios一键打包的文章,突然想想自己每次从打包...
    光彩影阅读 5,601评论 1 42
  • 亲爱的宝贝,你好! 今天一大早起来你又哭了,因为我没有五点钟叫你起床写作业。可是宝贝,你除了日记外,昨天其它作业不...
    91b6f8355762阅读 193评论 0 0