fastlane
Comment##使用背景
早些时候我一直使用python执行脚本来完成项目的持续集成,在Apple发布Xcode9的时候脚本进行了更新,部分脚本被废弃,在那时候我转移到fastlane阵营,原因很简单,fastlane使用更简单,更方便,我不再需要因为苹果对脚本的更新来被迫修改我的方案。
##fastlane介绍
fastlane是一款持续集成工具,它的功能强大,使用简单,可以帮助我们处理一些费时的工作,比如生成截屏、处理配置文件、编译App、上传测试分发平台等。
fastlane is a tool for iOS and Android developers to automate tedious tasks like generating screenshots, dealing with provisioning profiles, and releasing your application.
###开始使用fastlance
####安装fastlance
安装Xcode command line tool的最新版本1
xcode-select —install
使用工具安装fastlance1
2
3
4
5#使用gem安装(确保你已经安装了ruby)
sudo gem install fastlane -NV
#或者使用Homebrew安装(确保已经安装了Homebrew)
brew cask install fastlane
####配置fastlane
在terminal中进入你的项目目录,执行以下代码:1
fastlane init
接下来会根据你在安装时候的不同选择来创建不同的文件
- screenshots
- TestFlight
- AppStore
- Manual
这里选择4.Manual就好了,其他的功能后续也可以在配置文件中手动添加
其中最需要注意的文件是fastlane/Fastfile,其中包含了你将要操作的所有信息
####接下来要怎么做?
fastlane创建了所有的必要文件给我们,现在你可以通过配置这些文件进行持续化集成
###使用fastlane部署测试项目
####编译
fastlane 使用一个叫build_app的action来编译app,只要在Fastfile中加入下边代码:1
2
3lane :beta do
build_app(scheme: "MyApp")
end
还可以在编译的时候加入其他的选项1
2
3
4
5ane :beta do
build_app(scheme: "MyApp",
workspace: "Example.xcworkspace",
include_bitcode: true)
end
####上传app
在编译完成后可以上传到你选择的分发测试平台,在fastlane你可以很简单的做到这个工作,甚至不需要做额外的工作就可以同时上传多个平台
你可以选择上传的TestFlight,蒲公英,Fir,我们这里以蒲公英来举例:
在这里你可以找到蒲公英的上传文档,
你需要执行以下代码安装蒲公英插件
···
fastlane add_plugin pgyer
修改Fastfile,在build_app后添加蒲公英代码1
2
3
4lane :beta do
build_app(export_method: "ad-hoc")
pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")
end
做完这些配置后,你就可以通过fastlane来打包App,并自动上传到蒲公英,执行1
fastlane beta,
你可以打开蒲公英,查看蒲公英提供的更多配置,比如添加密码,添加更新描述等。
接下来我会提供一个我正在用的Fastfile为大家提供参考1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16default_platform(:ios)
platform :ios do
lane :test do
#添加版本更新描述
puts "请输入版本描述:"
#获取输入的描述
desc = STDIN.gets
#依次配置workspagce,scheme,build configuration,和export_method
build_app(workspace: "ProjectsName.xcworkspace", scheme: "ProjectsName", configuration: "Debug",export_method: "development")
#配置蒲公英的api_key,user_key,和输入的版本更新描述
pgyer(api_key: "59aa772ac06fe663xxxxxxxxxxxxxxx", user_key: "0b18ced68eb3cc7xxxxxxxxxxxxxxxxxx", update_description: "#{desc}")
end
end
###总结
App的编译、打包、上传无趣又费时,使用fastlane可以提升效率,又可以节省我们的时间,不需要为了后续的操作一直盯着电脑。fastlane使用比较方便,这里我只是做一个简单的介绍,当然fastlane还提供了更多的功能,你可以在fastlane主页和fastlane github中找到更多的详细配置。