iOS Fastlane教程(一):从安装到上传蒲公英

一、安装fastlane

1、终端输入:gem install fastlane
2、报错如下:

Could not find a valid gem 'fastlane' (>= 0), here is why:
          Unable to download data from https://gems.ruby-china.org/ - bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)

3、发现是因为gem源地址更改了,那么咱么切换为新的gem 源地址,终端修改gem sources :

gem sources --remove https://gems.ruby-china.org/

gem sources -a https://gems.ruby-china.com

修改后终端查看并确认下是否已经切换为新的sources:gem sources

4、切源成功后,继续终端输入:gem install fastlane,发现文件写入权限错误,错入如下:

Fetching: slack-notifier-2.3.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
    

5、使用带sudo的命令:
sudo gem install -n /usr/local/bin fastlane 然后输入管理员密码。
6、安装成功。查看版本 fastlane -v

zhangzhongdeMBP:~ ben$ fastlane -v
fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.125.2/bin/fastlane
-----------------------------
[⠙] 🚀 Ignoring ffi-1.9.25 because its extensions are not built. Try: gem pristine ffi --version 1.9.25
[✔] 🚀 
fastlane 2.125.2

二、初始化

1、终端cd到工程目录 然后输入初始化命令
fastlane init,终端执行会出现如下信息:

[19:21:07]: Sending anonymous analytics information
[19:21:07]: Learn more at https://docs.fastlane.tools/#metrics
[19:21:07]: No personal or sensitive data is sent.
[19:21:07]: You can disable this by adding `opt_out_usage` at the top of your Fastfile
[✔] Looking for iOS and Android projects in current directory...
[19:21:07]: Created new folder './fastlane'.
[19:21:07]: Detected an iOS/macOS project in the current directory: 'MultiScreen.xcworkspace'
[19:21:07]: -----------------------------
[19:21:07]: --- Welcome to fastlane 🚀 ---
[19:21:07]: -----------------------------
[19:21:07]: fastlane can help you with all kinds of automation for your mobile app
[19:21:07]: We recommend automating one task first, and then gradually automating more over time
[19:21:07]: 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
?

2、会出现4个选项让我们选择,询问我们使用fastlane来做什么用途,这4个选项分别代表什么意思呢:

1. 帮我们自动截取APP中的截图,并添加手机边框(如果需要的话),我们这里不选择这个选项,因为我们的项目已经有图片了,不需要这里截屏。 
2. 自动发布beta版本用于TestFlight
3. 自动的App Store发布包。
4. 手动设置。

3、我先选择了3来试一下,由于我的工程用workspace 管理,而且workspace下有好几个项目,所以终端出现下面信息让我Select Scheme:

[19:21:08]: ----------------------------------------------------------
[19:21:08]: --- Setting up fastlane for iOS App Store distribution ---
[19:21:08]: ----------------------------------------------------------
[19:21:08]: Parsing your local Xcode project to find the available schemes and the app identifier
Select Scheme: 
1. MultiScreen
2. TCastDemo
3. TCastSDK
4. TCLBIReport

4、我选择了项目1,终端继续执行:

[19:22:56]: ----------------------------------------------------------
[19:22:56]: --- Setting up fastlane for iOS App Store distribution ---
[19:22:56]: ----------------------------------------------------------
[19:22:56]: Parsing your local Xcode project to find the available schemes and the app identifier
[19:22:56]: $ xcodebuild -showBuildSettings -workspace MultiScreen.xcworkspace -scheme MultiScreen
[19:22:59]: Command timed out after 3 seconds on try 1 of 4, trying again with a 6 second timeout...
[19:23:03]: $ cd /Users/ben/TCL/T-Cast/Code/TCast/MultiScreen && agvtool what-version -terse
[19:23:04]: --------------------------------
[19:23:04]: --- Login with your Apple ID ---
[19:23:04]: --------------------------------
[19:23:04]: To use App Store Connect and Apple Developer Portal features as part of fastlane,
[19:23:04]: we will ask you for your Apple ID username and password
[19:23:04]: This is necessary for certain fastlane features, for example:
[19:23:04]: 
[19:23:04]: - Create and manage your provisioning profiles on the Developer Portal
[19:23:04]: - Upload and manage TestFlight and App Store builds on App Store Connect
[19:23:04]: - Manage your App Store Connect app metadata and screenshots
[19:23:04]: 
[19:23:04]: Your Apple ID credentials will only be stored in your Keychain, on your local machine
[19:23:04]: For more information, check out
[19:23:04]:     https://github.com/fastlane/fastlane/tree/master/credentials_manager
[19:23:04]: 
[19:23:04]: Please enter your Apple ID developer credentials
[19:23:04]: Apple ID Username:

5、输入用户名和密码后,打印如下:

[19:24:44]: Logging in...
Password (for 12345@test.com): ********
Two-factor Authentication (6 digits code) is enabled for account '123456@text.com'
More information about Two-factor Authentication: https://support.apple.com/en-us/HT204915

If you're running this in a non-interactive session (e.g. server or CI)
check out https://github.com/fastlane/fastlane/tree/master/spaceship#2-step-verification

(Input `sms` to escape this prompt and select a trusted phone number to send the code as a text message)

(You can also set the environment variable `SPACESHIP_2FA_SMS_DEFAULT_PHONE_NUMBER` to automate this)
(Read more at: https://github.com/fastlane/fastlane/blob/master/spaceship/docs/Authentication.md#auto-select-sms-via-spaceship-2fa-sms-default-phone-number)

Please enter the 6 digit code:

6、我选择输入sms,然后填好短信验证码之后继续执行:

Requesting session...
[19:26:25]: ✅  Logging in with your Apple ID was successful
[19:26:25]: Checking if the app 'com.tcl.universal.nScreen' exists in your Apple Developer Portal...
[19:26:26]: ✅  Your app 'com.tcl.universal.nScreen' is available in your Apple Developer Portal
[19:26:26]: Checking if the app 'com.tcl.universal.nScreen' exists on App Store Connect...
[19:26:28]: ✅  Your app 'com.tcl.universal.nScreen' is available on App Store Connect
[19:26:28]: ----------------------------
[19:26:28]: --- Manage app metadata? ---
[19:26:28]: ----------------------------
[19:26:28]: Would you like to have fastlane manage your app's metadata?
[19:26:28]: If you enable this feature, fastlane will download your existing metadata and screenshots.
[19:26:28]: This way, you'll be able to edit your app's metadata in local `.txt` files.
[19:26:28]: After editing the local `.txt` files, just run fastlane and all changes will be pushed up.
[19:26:28]: If you don't want to use this feature, you can still use fastlane to upload and distribute new builds to the App Store
[19:26:28]: Would you like fastlane to manage your app's metadata? (y/n)

6、我选择了'y',继续向下执行,打印一堆东西,在finder可以看到Fastlane为我们下载了itunce connect中已经存在的截图,还有相关的信息,如app介绍、app icon、公司信息、联系人信息等等。另外提示我没有做automatic version incrementing,然后继续等待 bundle update(这个过程有点慢)

[19:26:44]: Successfully created new configuration files.
[19:26:46]: Successfully downloaded large app icon
[19:26:46]: Downloading all existing screenshots...
[19:26:49]: Downloading existing screenshot '1_iphone65_1.1.png' for language 'zh-Hans'
[19:26:51]: Downloading existing screenshot '2_iphone65_2.2.png' for language 'zh-Hans'
[19:26:54]: Downloading existing screenshot '3_iphone65_3.3.png' for language 'zh-Hans'
[19:27:00]: Downloading existing screenshot '4_iphone65_4.4.png' for language 'zh-Hans'
[19:27:07]: Downloading existing screenshot '1_iphone6Plus_1.1.png' for language 'zh-Hans'
[19:27:10]: Downloading existing screenshot '2_iphone6Plus_2.2.png' for language 'zh-Hans'
[19:27:12]: Downloading existing screenshot '3_iphone6Plus_3.4.png' for language 'zh-Hans'
[19:27:15]: Downloading existing screenshot '4_iphone6Plus_4.5.png' for language 'zh-Hans'
[19:27:17]: Successfully downloaded all existing screenshots
[19:27:17]: Successfully created new Deliverfile at path './fastlane/Deliverfile'
[19:27:17]: It looks like your project isn't set up to do automatic version incrementing
[19:27:17]: To enable fastlane to handle automatic version incrementing for you, please follow this guide:
[19:27:17]:     https://developer.apple.com/library/content/qa/qa1827/_index.html
[19:27:17]: Afterwards check out the fastlane docs on how to set up automatic build increments
[19:27:17]:     https://docs.fastlane.tools/getting-started/ios/beta-deployment/#best-practices
[19:27:17]: Installing dependencies for you...
[19:27:17]: $ bundle update

bundle update过程慢的无法接受,我已经等了40分钟。可能又是被墙掉了,那咱们打开项目文件夹,找到fastlane init过程中生成的Gemfile文件,并打开:

source "https://rubygems.org"

gem "fastlane"

修改为:

source "https://gems.ruby-china.com"

gem "fastlane"

接着终端继续输入:bundle update,报了下面的问题:

Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password: 

输入密码后:

Installing json 2.2.0 with native extensions
Using mini_magick 4.5.1
Using multi_xml 0.6.0
Using plist 3.5.0
Using rubyzip 1.2.3
Using security 0.1.3
Using naturally 2.2.0
Using simctl 1.6.5
Using slack-notifier 2.3.2
Using terminal-notifier 2.0.0
Using unicode-display_width 1.6.0
Using terminal-table 1.8.0
Using tty-screen 0.7.0
Using tty-cursor 0.7.0
Using tty-spinner 0.9.1
Using word_wrap 1.0.0
Using nanaimo 0.2.6
Using xcodeproj 1.10.0
Using rouge 2.0.7
Using xcpretty 0.3.0
Using xcpretty-travis-formatter 1.0.0
Using fastlane 2.125.2
Bundle updated!

到此 fastlane init成功了,会出现在目录下出现了Gemfile.lock文件和Fastfile文件。

三、上传 App 到蒲公英

1、在终端输入:fastlane add_plugin pgyer命令,安装蒲公英的 fastlane 插件。
2、在终端提示Successfully installed plugins之后。
我们用 vim 打开:
vim ./fastlane/Fastfile

我们找到我们在用的工作流(action),在 build_app 指令后,加入蒲公英插件的配置信息。例如:

  desc "打包到蒲公英"
  lane :pgy do
  build_app(export_method: "ad-hoc")
  pgyer(api_key: "1234567890", user_key: "1234567890")
  end

3、以上的 api_keyuser_key,请开发者在自己账号下的 应用管理 - App概述 - API 中可以找到,并替换到以上相应的位置。配置好之后,终端执行fastlane pgy命令, 终端一顿执行之后又报错了:

[21:12:43]: 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    | build_app        | 197         |
+------+------------------+-------------+

[21:12:43]: fastlane finished with errors

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

3、原来是要在工程目录下面安装蒲公英插件,在工程目录fastlane add_plugin pgyer后,接着重新执行fastlane pgy。终端一顿执行,时不时报出一些警告信息,但美好的事情最终还是发生了:

[21:23:40]: Successfully exported and compressed dSYM file
[21:23:40]: Successfully exported and signed the ipa file:
[21:23:40]: /Users/ben/TCL/T-Cast/Code/TCast/TCLTV.ipa
[21:23:40]: -------------------
[21:23:40]: --- Step: pgyer ---
[21:23:40]: -------------------
[21:23:40]: The pgyer plugin is working.
[21:23:40]: build_file: /Users/ben/TCL/T-Cast/Code/TCast/TCLTV.ipa
[21:23:40]: Start upload /Users/ben/TCL/T-Cast/Code/TCast/TCLTV.ipa to pgyer...
[21:23:49]: Upload success. Visit this URL to see: https://www.pgyer.com/bucG

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
| 2    | build_app        | 180         |
| 3    | pgyer            | 8           |
+------+------------------+-------------+

[21:23:49]: fastlane.tools finished successfully 🎉
zhangzhongdeMBP:TCast ben$ 

4、浏览器打开蒲公英相应的应用界面,刷新后可以看到新版本已经通过fastlane上传成功。

四、总结

虽然这次试验,只用到了自动打包上传到蒲公英,但在过程中感受到了Fastlane的强大,后续还会对Fastlane做进一步的研究和学习。

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

推荐阅读更多精彩内容