Fastlane 是一套使用Ruby写的自动化工具集,旨在简化Android和iOS的部署过程,自动化你的工作流。它可以简化一些乏味、单调、重复的工作,像截图、代码签名以及发布App。方法简单粗暴,直接教你如何使用:
- 安装xcode命令行工具
$ xcode-select --install
如果没有安装,会弹出对话框,点击安装。如果已经安装提示xcode-select: error: command line tools are already installed, use "Software Update" to install updates
image
- 安装Fastlane
$ sudo gem install fastlane -NV
或
$ brew cask install fastlane
安装完毕后执行fastlane --version,确认下是否安装完成和当前使用的版本号(fastlane 2.99.1)。
- 初始化Fastlane
cd到你的项目目录执行$ fastlane init
当出现 What would you like to use fastlane for?1. ... 2. ... 3. Automate App Store Distribution 4. ...
选择3,然后接着输入你的开发者账号和密码,登录后会提示你是否需要下载你的App的metadata。输入y等待就可以。
这个时候可能会出现 fastlane init failed ,就问问你 Would you like to fallback to a manual Fastfile? 那么继续选择 y 接着几次enter就可以了。
- fastlane文件出现
初始化成功后会在当前工程目录生成一个fastlane文件夹,文件目录为下。
metadata和screenshots分别对应App元数据和商店应用截图。
Appfile主要存放App的apple_id team_id
app_identifier等信息
Deliverfile中为发布的配置信息,一般情况用不到。
Fastfile是我们最应该关注的文件,也是我们的工作文件。
- Fastfile的配置
fastlane_version "2.99.1"
default_platform(:ios)
now = Time.new.strftime("%Y_%m_%d_%H_%M_%S")
scheme = "你的项目的scheme"
api_key = "蒲公英账号上面的api_key"
user_key = "蒲公英账号上面的user_key"
platform :ios do
desc "Description of what the lane does"
#这个地方的lane:custom_lane你需要特别注意,后面执行打包的时候需要用到这个custom_lane
lane :custom_lane do
gym(
scheme: "#{scheme}",
#输出的ipa名称
output_name:"#{now} #{scheme}",
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method:"development",#这里我只是想打包到蒲公英上面做一个测试包,所以选择developement,如果你要发布到AppStore,你就要选择app-store
# 指定输出文件夹
output_directory:"./fastlane/build",
)
puts "开始上传蒲公英"
pgyer(api_key: "#{api_key}", user_key: "#{user_key}")
end
end
- 配置蒲公英插件
要实现自动打包到蒲公英平台,需要给fastlane安装个蒲公英插件,更多配置查看蒲公英文档$ fastlane add_plugin pgyer如果未添加蒲公英插件,则后面会报错,说找不到pgyer插件
- 执行打包
$ fastlane custom_lane desc:测试打包
出现
就上传到蒲公英上面成功了。
