作为一位iOS开发者,或者自动化测试工作者,大家都或多或少的接触或者听说过fastlane,今天主要讲一下fastlane的最基本使用和登陆校验问题!
什么是fastlane
fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.
怎么安装
// 安装最新的Xcode command line tools
xcode-select --install
// 安装 fastlane
sudo gem install fastlane -n /usr/local/bin
基础使用场景
- 上传testflight
- 上传apple store
- fastlane自有action
- 自定义 action
- 自定义上传私有库Action
- 内网分发
- ...
使用
假设我们从来没有使用过fastlane,我们来总结一下步骤:
-
进入一个Xcode项目跟目录
-
执行
fastlane init
fastlane init 新版本安装的时候出现了下面的分支选择,按要求选择就行 1. 📸 Automate screenshots 2. 👩✈️ Automate beta distribution to TestFlight (自动testfilght型配置) 3. 🚀 Automate App Store distribution (自动发布型配置) 4. 🛠 Manual setup - manually setup your project to automate your (需要手动配置内容) 3 [10:42:34]: Please enter your Apple ID developer credentials [10:42:34]: Apple ID Username: xxxxxxx@126.com [10:43:17]: Logging in... [10:43:22]: ✅ Logging in with your Apple ID was successful 由于我之前配置过账号密码,所以直接就通过了 ,剩下的步骤随便选择
-
执行
fastlane release
,愉快的等待打包上传的过程 -
如果账号没有开启两步验证的话,到这里,整个打包过程就结束了.但是作为开发者的我们,经历过去年 apple的一轮协议更新,主账号一般都开启了两步验证了,因此我们非常悲催的发现一个场景,在链接
apple connect
的时候,它报错了[12:00:06]: Login to App Store Connect (XXXXXXXX@163.com) [12:00:13]: Login successful [12:00:18]: [32mReady to upload new build to TestFlight (App: 100000000)...[0m [12:00:23]: Fetching password for transporter from environment variable named `FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD` [12:00:23]: Going to upload updated app to App Store Connect [12:00:23]: [32mThis might take a few minutes. Please don't interrupt the script.[0m [12:00:34]: [31m[Transporter Error Output]: Your Apple ID or password was entered incorrectly. (-20101) [0m [32m-------------------------------------------------------------------------------------[0m [32mPlease provide your Apple Developer Program account credentials[0m [32mThe login information you enter will be stored in your macOS Keychain[0m [32mYou can also pass the password using the `FASTLANE_PASSWORD` environment variable[0m [32mSee more information about it on GitHub: https://github.com/fastlane/fastlane/tree/master/credentials_manager[0m [32m-------------------------------------------------------------------------------------[0m
-
登录账号管理获取app专用密码 appleid.apple.com/account/man…
-
编辑zshrc文件
open ~/.zshrc
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh alias code='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code' # 添加全局变量 export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=App专用密码
执行下
source ~/.zshrc
-
获取
FASTLANE_SESSION
fastlane spaceauth -u appleId Logging into to App Store Connect (xxxxxxxx@163.com)... Available session is not valid any more. Continuing with normal login. Successfully logged in to App Store Connect --- Pass the following via the FASTLANE_SESSION environment variable: ---\n- !ruby/object:HTTP::Cookie\n name: DES5615ee1ca80587ae9a69d81e576853164\n value: HSARMTKNSRVXWFlaEvzCiaueSue3lJT7k2RbYnFJWaPCa50RJ4/qZ/Rh+pWnT0xLd+ePTS+i0ax6lBWEDVFs4mkv0YvOz1vJ56g126teanj4GLP+zwxZ5zksmVgxJ9TSb5BsoxuNSRVX\n domain: idmsa.apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 2592000\n created_at: 2019-11-05 17:27:39.027306000 +08:00\n accessed_at: 2019-11-06 10:10:33.027385000 +08:00\n- !ruby/object:HTTP::Cookie\n name: myacinfo\n value: DAWTKNV284d18c02b8b7e0ca9687a20890887b33ce164be953177dca4d54b1d8a34b306c7cdd46176f09b8c9ad921de647d38cc83c8446ae8937cf86fd205645a8e95d91a29821136c1181fd68b8d39b57dda5f5f84b7159c10ebd1e255b2fe54c07554d48968d98efaed82f3e97fbafad209a7bc8de3f4326a9ea76d919e1951463092e7b300e3edd95514182808a1ea951abd7d548e02da08cd9e5e359586d466c7c3ab32862e7a3c606e9945b9213e882ffa2fd5c8d8864178a0525e9d3f1ab2bdffab62aa3584fe1e1cedb047ee709095216bc432ac19c1c1416aec3edc87cc8de22491094d283fcf41b6f9f737205a8d26c24760ec14de91a14412f4ce751f4fd0e36326661663463336263393834623365356133386331373638303164666633633539353862663766MVRYV2\n domain: apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: \n created_at: 2019-11-06 10:10:35.096023000 +08:00\n accessed_at: 2019-11-06 10:10:35.097007000 +08:00\n- !ruby/object:HTTP::Cookie\n name: dqsid\n value: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzMwMDYyMzUsImp0aSI6IjdJTWVKdXJmWjVWNk9fNmh1QWR6RncifQ.LHAoqXse1mFQY5DEr4PcuzFRf0juWFXrFYdur1kDFW8\n domain: appstoreconnect.apple.com\n for_domain: false\n path: "/"\n secure: true\n httponly: true\n expires: \n max_age: 1799\n created_at: &1 2019-11-06 10:10:36.292923000 +08:00\n accessed_at: *1\n Example: export FASTLANE_SESSION='XXX'
-
编辑.zshrc文件
open ~/.zshrc
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh alias code='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code' # 添加全局变量 export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=App专用密码 #添加FASTLANE_SESSION export FASTLANE_SESSION='XXX'
执行下
source ~/.zshrc
-
Finished!
需要注意的地方:
针对于开启两步验证的问题,需要注意的是 FASTLANE_SESSION
是有有效期的, 现在的有效期是一个月,如果发现FASTLANE_SESSION
无效的时候需要重新生成下FASTLANE_SESSION
.
一个trick
既然二步验证后,FASTLANE_SESSION
存在过期时间,那么我们可以新建一个子账号,不开启两步验证即可规避,实际验证是可行的! 不过有一点需要确认,电脑上安装的证书包含该账号!
预告
下一节讲一下 fastlane match
来管理证书,来规避一些证书管理导致的风险和问题!
A new approach to iOS code signing: Share one code signing identity across your development team to simplify your codesigning setup and prevent code signing issues.