iOS接入fastlane简易版教程

fastlane 是什么?

一套使用Ruby写的自动化工具集,旨在简化Android和iOS的部署过程,自动化你的工作流。它可以简化一些乏味、单调、重复的工作,像截图、代码签名以及发布App

fastlane 可以干什么

插件 功能
gym 是fastlane提供的打包工具。
snapshot 生成多个设备的截图文件
frameit 对截图加一层物理边框
increment_build_number 自增build number 然后与之对应的get_build_number。Version number同理。
cert: 创建一个新的代码签名证书
sigh: 生成一个provisioning profile并保存打当前文件
pem: 确保当前的推送证书是活跃的,如果没有会帮你生成一个新的
match: 在团队中同步证书和描述文件。(这是一种全新的管理证书的方式)
testflight: 上传ipa到testflight
deliver: 上传ipa到AppStore

fastlane 安装指南

gem 安装fastlane

1
sudo gem install fastlane

新项目安装fastlane

1
fastlane init

fastlane打包

打包需要条件

条件 名称 是否必须
工程名 DailyClock
包名 打卡
打包环境 Debug
teamID M99LZTCK8N
provisioningProfiles {“com.chengyan.DailyClock” => “DailyClockAppStore”}
以下是上传蒲公英需要的参数
蒲公英的appid ****
蒲公英的userkey **
以下是上传appstore需要准备的参数
用户名 xxxxxx@xx.com
密码 xxxxx
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD xxxx
FASTLANE_SESSION xxx

可能遇到的问题

  1. 怎么获取 FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD?

    访问苹果账号管理添加app专用的密码

  2. 怎么获取FASTLANE_SESSION?

    命令行执行如下命令:fastlane spaceauth -u yourappleid

  3. command timed out after 10 seconds on try 1 of 4
    原因: 很大可能是机器不给力了,使xcodebuild -showBuildSettings ?

-workspace ./XX.xcworkspace -scheme XX -configuration Release
命令执行超时
解决方法: 在Fastfile的 before_all方法中,添加 :

1
2
ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120"
ENV["FASTLANE_XCODEBUILD_SETTINGS_RETRIES"] = "4"

一些范例


范例一、打包app并上传到蒲公英平台

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 desc "Description of what the lane does"
lane :dk do
ipa_dir = "fastlane_build/"
ipa_name = "打卡"+Time.new.strftime('%Y-%m-%d_%H:%M')
archive_path = "./build/ipa/tem/archive/DailyClock.xcarchive"

increment_build_number(xcodeproj:"DailyClock.xcodeproj")
build_app(workspace:"DailyClock.xcworkspace",
scheme:"DailyClock",
configuration:"Debug",
clean: true,
output_directory:ipa_dir,
archive_path:archive_path,
export_options:{
method:"development",
destination: "export",
stripSwiftSymbols: true,
teamID: "M99LZTCK8N",
uploadBitcode: false,
uploadSymbols: true,
provisioningProfiles: {"com.chengyan.DailyClock" => "DailyClockDev"}
}
)
# 发布到蒲公英平台
pgyer(api_key:"替换为你的蒲公英平台的appkey",user_key:"替换为你自己的userkey")

end

范例二、打包app上传到appstore

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
desc "app store"
lane:release do
ENV["FASTLANE_USER"] = "your appleid"
ENV["FASTLANE_PASSWORD"] = "password"
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "yourpasssword"
ENV["FASTLANE_SESSION"] = '''yoursession'''
ipa_dir = "fastlane_build/"
ipa_name = "测一测"+Time.new.strftime('%Y-%m-%d_%H:%M')
archive_path = "./build/ipa/tem/archive/xxx.xcarchive"

increment_build_number(xcodeproj:"xxx.xcodeproj")
build_app(workspace:"xxx.xcworkspace",
scheme:"xxx",
configuration:"Release",
clean: true,
output_directory:ipa_dir,
archive_path:archive_path,
export_options:{
method:"app-store",
destination: "export",
stripSwiftSymbols: true,
teamID: "xxx",
uploadBitcode: false,
uploadSymbols: true,
provisioningProfiles: {"xxxx"}
}
)
upload_to_testflight(
ipa: ipa_dir+'/grh.ipa',
skip_waiting_for_build_processing: true
)

end

成功截图

命令执行

1
2
fastlane release # 打包并发布appstore
fastlane dk #打包并发布到蒲公英

更多

结合alfred效率神器,打包将更香。最终效果


真香!!!

作者

火三

发布于

2022-07-28

更新于

2022-07-28

许可协议