使用条件
- 确保xcode命令行工具已安装
xcode-select --install
- 两种安装fastlane的方法
# Using RubyGems
sudo gem install fastlane -NV
# Alternatively using Homebrew
brew install fastlane
第一步
- 到项目中初始化fastlane
//执行完这条,你的项目就会有fastlane的几个文件,具体有什么文件,看初始化时的配置
fastlane init
// swift项目使用这条
fastlane init swift
必备功能
- 对我来说必备功能就是自动打包,然后上传到fir或者蒲公英,至于那些截图,或者用match来管理证书等都是辅助功能,所以我放到辅助功能中讲解。
签名
-
方式1:使用match自动管理
- 我这里不去用这个,因为会要revoke掉之前的证书
- 使用match方法【展示不用,因为需要revoke已存在的证书,如果你需要使用match来管理证书,可以参考这篇文章:[juejin.cn/post/684490…]】
-
方式2:使用cert和sigh方法
- 第一步:配置好项目
- 手动管理签名的参考配置-推荐(If you don't use match, we recommend defining a mapping of app target to provisioning profile in your Fastfile. By defining those profiles, you can guarantee reproducible builds every time you run it.)
- 自动管理签名的参考配置-可能会有问题(You can also use Xcode’s Automatically Manage Signing feature. By default, automatic signing via xcodebuild is disabled. To enable it, pass -allowProvisioningUpdates via the export_xcargs option:)
-
手动管理签名的参考配置-推荐
// 官方配置参考
lane :beta do
build_app(
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.example.bundleid" => "Provisioning Profile Name",
"com.example.bundleid2" => "Provisioning Profile Name 2"
}
}
)
end
// 自己配置,这里的xbb_dev是证书的名字
// 注意:export_method需要和证书相对应,如果是开发的模式,那么使用开发的证书;如果是appstore的,就需要使用appstore的证书;如果是ad-hoc的,就需要使用ad-hoc的证书。
lane :beta do
build_app(
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.xbks.test" => "xbks test dis"
}
}
)
end
- 自动管理签名的参考配置-可能会有问题
lane :beta do
build_app(export_xcargs: "-allowProvisioningUpdates")
end
第二步
- 打包一个ipa包出来,使用的命令,下面的命令可以打包一个ipa包出来,亲测,xbks test dis就是appstore对应的证书文件。
lane :beta do
build_app(
scheme: "qmuidemo",
export_method: "app-store",
export_options: {
provisioningProfiles: {
"com.xbks.test" => "xbks test dis"
}
}
)
end
第三步
- 安装插件
// 安装蒲公英
fastlane add_plugin pgyer
参考指令
- build_app()括号内可以配置的参数
// 有这些导出的类型,需要有相应的证书配对才能导出成功ipa。
// app-store, ad-hoc, package, enterprise, development, developer-id
export_method:"development"
// 如果要使用ad-hoc打包, 则需打开此项配置
sigh(adhoc:true)
// 导出的ipa名字
output_name: ouput_name
// 导出的ipa位置
output_directory: '/Users/coderiding/Downloads/Temp'
//
scheme: "xbb"
// 可省略
workspace: "xbb.xcworkspace"
// 如果使用自动签名,需要配置这句
export_xcargs: "-allowProvisioningUpdates"
//
export_options: {}
// 是否清空上次打包信息
clean: true
// 配置开发模式还是发布模式:Debug or Release
configuration: "Debug"
- 其他命令
// 打包命令
fastlane releaseDev descprition:" 优化代码块xx"
// 如果要使用ad-hoc打包, 则需打开此项配置
sigh(adhoc:true)
Time.new.strftime("%Y%m%d%H%M%S")
get_version_number
version = get_version_number(
xcodeproj: "xbks.xcodeproj",
target: "xbks"
)
get_build_number(xcodeproj: "xbb.xcodeproj")
increment_build_number
sync_code_signing
build_app
capture_screenshots
disable_automatic_code_signing(path: "my_project.xcodeproj")
enable_automatic_code_signing(path: "my_project.xcodeproj")
upload_to_testflight
upload_to_app_store
// invokes cert ,invokes是调用的意思
get_certificates
// invokes sigh
get_provisioning_profile
// 获取推送证书
get_push_certificate
- 命令使用问题
- 问题1:使用increment_build_number,报错:Apple Generic Versioning is not enabled in this project.《《《《》》》》 解决:在 target -> building setting 中, 搜索 current project version, 出现 versioning system 选择 Apple Generic
辅助功能
功能:截图
- 利用UITest来截图
- Create a new UI Test target in your Xcode project (See the top part of this article) :先到项目中添加一个UITest的target,具体的方法百度,如果之前有,直接使用
- Run " fastlane snapshot init " in your project folder :执行fastlane snapshot init命令,开启截图的功能
- Add the ./SnapshotHelper.swift file to your UI Test target (You can move the file anywhere you want):项目中会生成SnapshotHelper.swift这个文件,把这个文件放到项目中,我是放到UITest target中的,这个文件的作用就是fasntlane帮你写好的截图方法类,因为它是用swift写,所以如果是oc项目,需要你自己添加桥接头文件,添加桥接头文件的方法就是直接在oc项目中创建一个swift文件,系统就会自动帮你创建桥接头文件。
- Add a new Xcode scheme for the newly created UI Test target:为UITest target添加一个scheme
- Edit the scheme:编辑scheme
- In the list on the left click "Build", and enable the checkbox under the "Run" column for your target.:选择左侧的Build选项,允许右侧我们的UITest scheme中的Run的选项,勾选。
- Enable the Shared box of the newly created scheme:开启UITest scheme的Shared选项
- (Objective C only) Add the bridging header to your test class.:如果是oc项目,需要执行这条,添加桥接头文件
- #import "xx-Swift.h":在启动UITest的位置,导入swift头文件,这里的xx指的是新建的UITest target的名字
- The bridging header is named after your test target with -Swift.h appended.
- In your UI Test class, click the Record button on the bottom left and record your interaction:点击记录按钮,开始测试,会进行截图,前提是在UI测试代码中加入了截图的功能,截图的功能,分为启动和埋点。
- To take a screenshot, call the following between interactions:这里就是截图功能中的埋点,在需要截图的地方,写下面的代码埋点。
- Swift: snapshot("01LoginScreen")
- Objective C: [Snapshot snapshot:@"01LoginScreen" timeWaitingForIdle:10];
- Add the following code to your setUp() method:下面的是截图功能中的启动方法
//Swift:
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
//Objective C:
XCUIApplication *app = [[XCUIApplication alloc] init];
[Snapshot setupSnapshot:app];
[app launch];
- 单独抽出来做个lane,执行这个lane就是截图和上传
lane :screenshots do
capture_screenshots
upload_to_app_store
end
//如果不通过lane来执行,可单独执行每一条指令
fastlane action capture_screenshots
fastlane action upload_to_app_store
- 单独上传到appstore
fastlane deliver
- 带手机框的截图
- This will only add a device frame around the screenshots
- If you want to upload the screenshots to the App Store, you have to provide a Framefile.json, with titles and background, otherwise the resolution of the framed screenshots doesn't match the requirements of App Store Connect.
fastlane frameit
// 使用这个功能,还需安装依赖的包
brew install libpng jpeg imagemagick
// 如果安装上面的包报错:mogrify: no decode delegate for this image format `PNG',按下面的再安装
brew uninstall imagemagick; brew install libpng jpeg; brew install imagemagick --build-from-source
// 下载最新的frameit
fastlane frameit setup
// 使用
lane :screenshots do
capture_screenshots
frame_screenshots(white: true)
upload_to_app_store
end
// 单独使用
fastlane action frame_screenshots
// 执行下面的代码会得到一组套黑色手机边框的图片
fastlane frameit
// 执行下面的代码会得到白色边框的图片
fastlane frameit silver
// 支持的手机框颜色
white\silver\rose_gold\gold
// 查询更多用法
fastlane action frameit
- 为截图自定义标题和背景
- 截图高级功能
// 更新截图helper文件
fastlane snapshot update
- 截图问题
- 问题1:Your Snapshot Helper file is missing, please place a copy
- 问题2:上传截图到appstore的时候,报错:Unexpected Error
slack介绍
- 任务完成后用来发送消息,及时告知你结果
- 这里用到一个slack网站来实现这个功能
- xbks.slack.com/apps/new/A0…
- 直接注册账号,根据提示获取到WebHook URL,这个需要在slack action中用到
// 单独发送一条消息,其中slack_url就是你上面获取到的WebHook URL
lane :slack_message do
slack(
message: "App successfully uploaded to iTunesConnect.",
success: true,
slack_url: "https://your slack incoming webhook url"
)
end
参考
- docs.fastlane.tools/
- docs.fastlane.tools/getting-sta…
- docs.fastlane.tools/getting-sta…
- docs.fastlane.tools/codesigning…
- docs.fastlane.tools/codesigning…
- www.jianshu.com/p/5d298523c…
- docs.fastlane.tools/actions/ 命令参考链接
- docs.fastlane.tools/plugins/ava… 插件参考链接,我就用了蒲公英
- www.pgyer.com/doc/view/fa… 蒲公英插件配置
- github.com/icyleaf/fas…
- docs.fastlane.tools/actions/sla…
- medium.com/ios-develop…