首先是官网地址
一、安装:
ruby -v
查看版本号,确保ruby的版本是最新的;
然后检查 Xcode 命令行工具是否安装。在终端窗口中输入命令:
xcode-select --install
最后通过sudo gem install fastlane
安装;
二、项目初始化
在终端进入项目的xcodeproj文件所在目录,执行fastlane init
,接下来就是一段问题和选项,一路点下去。
![](https://img.haomeiwen.com/i3286336/399eb85d78e0ee9c.png)
这里需要注意,选项1是自动生成屏幕截图,选项2是上传版本到testflight,选项3是上传到App Store。这里我们选择4.下面的就一路点下去即可。
完成后再目录下可看到生成的文件,主要包含两个Appfile和FastFile
Appfile用来存放app_identifier,apple_id和team_id。 了解详情,它的格式是这样的:
app_identifier "com.xxx.xxx" # app的bundle identifier
apple_id "xxx@xxx.com" # 你的Apple ID
team_id "XXXXXXXXXX" # Team ID
···
也可以为每个lane提供不同的 app_identifier, apple_id 和 team_id,例如:
app_identifier "com.aaa.aaa"
apple_id "aaa@aaa.com"
team_id "AAAAAAAAAA"
for_lane :inhouse do
app_identifier "com.bbb.bbb"
apple_id "bbb@bbb.com"
team_id "AAAAAAAAAA"
end
我的Fastfile编写如下,对于测试版本,每次打包可以自动增加版本号
default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
def updateProjectBuildNumber
currentTime = Time.new.strftime("%Y%m%d")
build = get_build_number()
if build.include?"#{currentTime}."
# => 为当天版本 计算迭代版本号
lastStr = build[build.length-2..build.length-1]
lastNum = lastStr.to_i
lastNum = lastNum + 1
lastStr = lastNum.to_s
if lastNum < 10
lastStr = lastStr.insert(0,"0")
end
build = "#{currentTime}.#{lastStr}"
else
# => 非当天版本 build 号重置
build = "#{currentTime}.01"
end
puts("*************| 更新build #{build} |*************")
# => 更改项目 build 号
increment_build_number(
build_number: "#{build}"
)
end
lane :dev do
# add actions here: https://docs.fastlane.tools/actions
updateProjectBuildNumber #// 这里调用
currentTime = Time.new.strftime("%Y-%m-%d-%H-%M")
ipaName = "UAT-#{currentTime}.ipa"
gym(
scheme: "wedo",
export_method:"development",
archive_path:"./build/uat",
output_directory:"./build/uat",
output_name:ipaName
)
end
desc "提交一个新的Beta版本到 Apple TestFlight"
desc "This will also make sure the profile is up to date"
lane :beta do
gym(scheme: "wedo") # Build your app - more options available
pilot
end
desc "部署一个新版本到App Store"
lane :release do
# match(type: "appstore")
# snapshot
gym(scheme: "wedo") # Build your app - more options available
deliver(force: true)
# frameit
end
desc "企业版"
lane :inHouse do
updateProjectBuildNumber #// 这里调用
currentTime = Time.new.strftime("%Y-%m-%d-%H-%M")
ipaName = "UAT-#{currentTime}.ipa"
gym(scheme: "wedo",
export_method:"enterprise",
output_directory "./build/uat", # 打包后的 ipa 文件存放的目录
output_name ipaName # ipa 文件名
)
end
end
对于不同的lane,每次执行的时候使用fastlane 名字
即可
网友评论