Fastlane 入门使用手册

一、安装xcode命令行工具

xcode-select --install,如果没有安装,会弹出对话框,点击安装。如果提示xcode-select: error: command line tools are already installed, use "Software Update" to install updates表示已经安装

二、安装Fastlane

sudo gem install fastlane -NV或是brew cask install fastlane我这里使用gem安装的

安装完了执行fastlane --version,确认下是否安装完成和当前使用的版本号。

安装pgy和fir插件,以便打包完成自动上传

fastlane add_plugin pgyer 
fastlane add_plugin firim

三、初始化Fastlane

cd到你的项目目录执行

fastlane init

这里会弹出四个选项,问你想要用Fastlane做什么? 之前的老版本是不用选择的。选几都行,后续我们自行根据需求完善就可以,这里我选的是3。

四、修改Fastfile,全局文件AppFile,多环境文件env

  1. 配置Fastfile
  • 因为我们是多target的项目,需要写多个gym

default_platform(:ios)

platform :ios do
  desc "Push a new release build to the App Store"
  lane :release do
    build_app(workspace: "Matafy.xcworkspace", scheme: "Matafy")
    # upload_to_app_store
  end


desc "打包到pgy"
lane :MatafyDev do |options|
sigh(adhoc:true)  #如果要使用ad-hoc打包, 则需打开此项配置
gym(
  clean:true, #打包前clean项目
  # export_method: "ad-hoc", #导出方式 # app-store, ad-hoc, package, enterprise, development, developer-id  
  export_method: ENV['METHOD'],
  # scheme:"MatafyDev", #scheme
  scheme: ENV['SCHEME_NAME'],
  configuration: "Release",#环境
  output_directory:"./app",#ipa的存放目录
  output_name:"Matafy Dev",#get_build_number()#输出ipa的文件名为当前的build号
  )
  #使用自动证书管理
  enable_automatic_code_signing(path: "Matafy.xcodeproj")
#蒲公英的配置 替换为自己的api_key和user_key
pgyer(api_key: "xxxxxxxx", user_key: "xxxxxxxxx",update_description: options[:desc])
end

desc "打包到fir"
lane :Matafy do |options|
sigh(adhoc:true)  #如果要使用ad-hoc打包, 则需打开此项配置
gym(
  clean:true, #打包前clean项目
  # export_method: "ad-hoc", #导出方式 # app-store, ad-hoc, package, enterprise, development, developer-id  
  export_method: ENV['METHOD'],
  # scheme:"MatafyDev", #scheme
  scheme: ENV['SCHEME_NAME'],
  configuration: "Release",#环境
  output_directory:"./app",#ipa的存放目录
  output_name:"Matafy",#get_build_number()#输出ipa的文件名为当前的build号
  )
  #使用自动证书管理
  enable_automatic_code_signing(path: "Matafy.xcodeproj")
#firim的配置    firim :8e6b56500b0fc122c9ce9007117a6055
firim(firim_api_token: "xxxxxxxxxx") #上传到firim
end

end
  1. 配置Appfile
app_identifier ENV['APP_IDENTIFIER']
apple_id ENV['APPLE_ID']
team_id ENV['TEAM_ID']
itc_team_id("xxxxxx") # App Store Connect Team ID
  1. 每个target建一个.env.target文件
APPLE_ID = "开发者账号"

FASTLANE_PASSWORD = "开发者密码"

TEAM_ID = "团队ID"

APP_IDENTIFIER ="Bundle Identifier"

SCHEME_NAME ="scheme名称"

METHOD = "ad-hoc"  #"打包方式,可选enterprise、app-store等"

注意要在manage scheme中把targets的shared选项勾上,不然还是默认打的第一个target

五、运行fastlane

  • 最后一条命令,搞定:
# 打测试包到pgy
fastlane MatafyDev Desc:dev4.0.2打包 --env MatafyDev
# 打正式包到fir
fastlane Matafy Desc:4.0.1 --env Matafy

上面命令意义为,fastlane 用matafyDev的gym运行,Desc为发布的描述(可为空), --env matafyDev 表示使用的是matafyDev这个环境变量来打包

补充:添加忽略文件:

#fastlane

# fastlane specific

**/fastlane/report.xml

# deliver temporary files

**/fastlane/Preview.html

# snapshot generated screenshots

**/fastlane/screenshots

# scan temporary files

**/fastlane/test_output

/app

/*.mobileprovision

你可能感兴趣的:(Fastlane 入门使用手册)