使用fastlane实现自动化打包上传到蒲公英

203 阅读2分钟

使用fastlane实现自动化打包上传到蒲公英

安装fastlane

使用brew install fastlane报错
curl: (22) The requested URL returned error: 404	
Warning: Bottle missing, falling back to the default domain...
 解决方案:
1. export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" 
2. brew update
3. brew install fastlane 

fastlane初始化

查看是否安装成功fastlane --version

cd到项目目录, 对项目进行初始化fastlane init(打开翻墙软件,不然会卡死在bundle update)

截屏2022-03-03 上午10.36.05.png

安装蒲公英插件 fastlane add_plugin pgyer

截屏2022-03-03 上午10.38.39.png

fastlane配置

打开项目里的fastlane文件夹 打开Fastfile文件

截屏2022-03-03 上午10.23.58.png

创建一个任务

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :custom_lane do
    # add actions here: https://docs.fastlane.tools/actions
  end
end

lane:custom_lane,代表了一个叫custom_lane的任务,后面的do,则表示需要执行的操作,我把我项目中的Fastfile贴上来:

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :dev do|options|      #给lane命名
  branch = options[:branch]

schemeName = "项目Target1"
export_method = "development"

api_key = "*************"
user_key = "************"

puts "请输入版本描述"
desc = STDIN.gets

puts "开始打包 #{schemeName}"
# 开始打包
gym(
#指定scheme的名字
scheme: "#{schemeName}",
#输出的ipa名称
output_name:"#{schemeName}",
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development

export_method:"#{export_method}",
# 指定输出文件夹,这里会保存我们最后生成的ipa文件,也就是存到了我们上面提到的fastlane文件夹中的build文件夹中
output_directory:"/Users/xinkejuhe-sunyueming/Desktop/资源/testipa",
)

puts "开始上传到蒲公英"
# password: 是蒲公英的安装密码,不设置默认安装没有密码
pgyer(update_description: "#{desc}", api_key: "#{api_key}", user_key: "#{user_key}", password: "1234", install_type: "2")
# 指定输出文件夹,这里会保存我们最后生成的ipa文件,也就是存到了我们上面提到的fastlane文件夹中的build文件夹中
system "open ./fastlane/build"
puts "上传蒲公英成功"
    # add actions here: https://docs.fastlane.tools/actions
  end
end

还有一个文件Appfile需要设置你的appid的账号和相关信息, 我把我项目中的Appfile贴上来:

官方文档

# app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app
# apple_id("[[APPLE_ID]]") # Your Apple email address


# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile



app_identifier "******"
apple_id "*******"
itunes_connect_id "*******"

team_id "****" # Developer Portal Team ID
itc_team_id "****" # App Store Connect Team ID