一、安装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 [email protected]): ********
Two-factor Authentication (6 digits code) is enabled for account '[email protected]'
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_key
和 user_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做进一步的研究和学习。