sudo gem install fastlane
sudo gem install fastlane -NV
以下两种终端更新Fastlane方式,使用一种即可:
bundle update fastlane
fastlane update_fastlane
sudo gem unstall fastlane
fastlane --version
which fastlane
fastlane init
fastlane cert create
fastlane add_plugin pgyer
Plugin 'fastlane-plugin-pgyer' was added to './fastlane/Pluginfile'
[10:08:29]: It looks like fastlane plugins are not yet set up for this project.
[10:08:29]: fastlane will modify your existing Gemfile at path 'Gemfile'
[10:08:29]: This change is necessary for fastlane plugins to work
[10:08:29]: Should fastlane modify the Gemfile at path 'Gemfile' for you? (y/n)
一般安装好蒲公英插件和fastlane初始化后会默认生成
source "https://rubygems.org"
gem "fastlane"
gem "cocoapods"
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
一般安装好蒲公英插件和fastlane初始化后会默认生成,可以按需求修改,个人的Apple ID方便接收AppStore上传及审核信息
app_identifier("com.xxx.xxx") #app的bundleID
apple_id("[email protected]") #个人的Apple ID,邮箱
itc_team_id("xxxxxx") #App Store的团队ID App Store Connect Team ID
team_id("xxxxxx") #团队ID Developer Portal Team ID
branch ENV['xxxxxx'] #分支
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
Fastfile文件为核心配置文件,需要编辑打包流程到信息,每一个功能块由 ==lane: xxx do ==开头 end 结尾
定义一个递增build号的函数,添加到Fastfile中
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
#fastlane版本号
fastlane_version "2.216.0"
#打包平台
default_platform :ios
#指定项目的scheme名称 ---- 修改
scheme="xxx"
#蒲公英api_key和user_key ---- 修改
api_key="xxx"
user_key="xxx"
# 任务脚本
platform :ios do
desc "以 development 方式打包并上传到蒲公英"
lane :test_beta do
puts "以 development 方式打包"
gym(
# 指定打包所使用的输出方式 (可选: app-store, package, ad-hoc, enterprise, development)
export_method: "development",
# 指定项目的 scheme 名称
scheme: "xxx",
# 指定输出的文件夹地址
output_directory: "./archive/test_beta/" + Time.new.strftime("%Y-%m-%d-%H:%M:%S"),
)
puts "上传 ipa 包到蒲公英"
pgyer(
# 蒲公英 API KEY
api_key: "xxx",
# 蒲公英 USER KEY
user_key: "xxx"
)
end
desc "以 ad-hoc 方式打包并上传到蒲公英"
lane :beta do
puts "自动生成 Provisioning Profiles 文件"
sigh(
# 指定输出的文件夹地址
output_path: "./archive/sign",
# 是否为 AdHoc 证书(设为 false 或不写默认为 AppStore 证书)
adhoc: true
)
puts "以 ad-hoc 方式打包"
gym(
# 指定打包所使用的输出方式 (可选: app-store, package, ad-hoc, enterprise, development)
export_method: "ad-hoc",
# 指定项目的 scheme 名称
scheme: "xxx",
# 指定输出的文件夹地址
output_directory: "./archive/beta/" + Time.new.strftime("%Y-%m-%d-%H:%M:%S"),
# 指定打包方式 (可选: Release, Debug)
configuration: "Release"
)
puts "上传 ipa 包到蒲公英"
pgyer(
# 蒲公英 API KEY
api_key: "xxx",
# 蒲公英 USER KEY
user_key: "xxx"
)
end
desc "以 app-store 方式打包并上传到 iTunes Connect"
lane :release do
puts "自动生成 Provisioning Profiles 文件"
sigh(
# 指定输出的文件夹地址
output_path: "./archive/sign"
)
puts "以 app-store 方式打包"
gym(
# 指定打包所使用的输出方式 (可选: app-store, package, ad-hoc, enterprise, development)
export_method: "app-store",
# 指定项目的 scheme 名称
scheme: "xxx",
# 指定输出的文件夹地址
output_directory: "./archive/release/" + Time.new.strftime("%Y-%m-%d-%H:%M:%S"),
# 指定打包方式 (可选: Release, Debug)
configuration: "Release"
)
puts "上传 ipa 包到 iTunes Connect"
deliver(
# 跳过截图上传
skip_screenshots: true,
# 跳过元数据上传
skip_metadata: true,
# 跳过审核直接上传
force: true
)
end
end
以上配置完成就可以在本地终端进行打包了,
打开终端进入到项目fastlane文件夹上一级,输入以下命令即可打一个以 development 方式打包并上传到蒲公英的包。
fastlane test_beta
一般安装好蒲公英插件后会默认生成
# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!
gem 'fastlane-plugin-pgyer'
把项目工程中所有的info.plist文件的路径中带有SRCROOT的路径全部改成相对路径,要不然会报错。
做 fastlane 命令的时候都是在项目的根目录下进行的,打开终端进入到项目fastlane文件夹上一级。
fastlane lanes
fastlane fastlane-credentials add --username felix@krausefx.com
//会自动要求输入密码:App-Specific Passwords
Password: *********(这里就是要输入刚刚生成的App-Specific Passwords)
如果手动输入错误:请执行以下命令:删除账号,再重复添加凭证,完成添加
fastlane fastlane-credentials remove --username felix@krausefx.com
//password has been deleted.
工具的使用没有什么技术含量,想研究fastlane代码可参考github
[!] Error uploading ipa file:
[Application Loader Error Output]: Error uploading '/var/folders/sp/_4jyc68d0hvbm70nm50ljvvw0000gp/T/3a982536-cad1-483e-8b64-5c74740a168f.ipa'.
[Application Loader Error Output]: Unable to upload archive. Failed to get authorization for username '[email protected]' and password. (
[Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure.