fastlane自动化打包发版以及上传至蒲公英

263 阅读3分钟

fastlane简介 组件pod发版本自动化文章已说明,这里就不再简述,直接开始操作步骤。 [TOC]

1.安装前的准备工作

1.1首先确认是否安装了ruby,终端查看下ruby版本Objc ruby -v 1.2确认是否安装了Xcode命令行工具Objc xcode-select --install 如果提示已安装就进行下一步,提示安装弹窗就进行安装。

2.安装fastlane

sudo gem install fastlane

3.现有工程fastlane初始化

cd到现有工程的根目录 Objc fastlane init 出现以下提示Objc [10:13:13]: What would you like to use fastlane for? 1. Automate screenshots 2. Automate beta distribution to TestFlight 3. Automate App Store distribution 4. Manual setup - manually setup your project to automate your tasks第一个选项的意思是:自动截屏。这个功能能帮我们自动截取APP中的截图,并添加手机边框(如果需要的话) 第二个选项的意思是:自动发布beta版本用于TestFlight 第三个选项的意思是:自动发布到AppStore 第四个选项的意思是:手动设置 选择第四个手动设置。 注意事项:如果卡在了build update,很有可能是gem sources的问题,以下解决方案:Objc gem sources --remove https://gems.ruby-china.com gem sources -a https://gems.ruby-china.com 你可以用 Bundler 的 Gem 源代码镜像命令。 $ bundle config mirror.https://rubygems.org https://ruby.taobao.org重新执行build update,或者fastlane init,直到文件目录结构出现Gemfile.lock。 紧接着一直点击enter键就行。 安装成功之后,会在我们的工程目录生成一个fastlane文件夹,然后此时,我们需要自己编辑Appfile和Fastfile两个文件。 以司机端为例,Appfile文件:Objc app_identifier("com.olayc.driver") # The bundle identifier of your app apple_id("806631463@qq.com") # Your Apple email address team_id "OLA Information Service Co., Ltd."Fastfile文件:

This file contains the fastlane.tools configuration
You can find the documentation at docs.fastlane.tools
For a list of all available actions, check out
docs.fastlane.tools/actions
For a list of all available plugins, check out
docs.fastlane.tools/plugins/ava…
Uncomment the line if you want fastlane to automatically update itself
update_fastlane

defaultplatform(:ios) platform :ios do #adhoc打包 desc "打包到pgy" lane :test do |options| gitpull buildiosapp( clean:true, #打包前clean项目 exportmethod: "ad-hoc", #导出方式 exportoptions: { provisioningProfiles: { "com.olayc.driver" => "driverxcode11", } }, scheme:"OLA-iOS Dev", #scheme configuration: "Release",#环境 outputdirectory:"./app",#ipa的存放目录 outputname:getbuild_number(),#输出ipa的文件名为当前的build号 )

蒲公英的配置 替换为自己的apikey和userkey

pgyer(apikey: "21b5ee9e41a604164871789668ff2d86", userkey: "00d42bbbeb279d0576c1356e70a2f888",update_description: options[:desc]) end end

4.fastlane自动化打包

编写完成这两个文件之后,因为要上传至蒲公英,需要安装fastlane中蒲公英的插件,在终端执行Objc fastlane add_plugin pgyer 安装完成后fastlane文件里会出现Pluginfile文件 然后在终端执行Objc fastlane test desc:测试打包 就可以自动化打包上传至蒲公英。 如果需要自动化发版本,在Fastfile文件中的export_method: "ad-hoc", #导出方式参数配成相应参数

5.fastlane自动化打包踩坑记录

5.1首先先明确自己电脑的xcode能否打包成功,如果不能先把证书、描述文件配置好。 5.2明确5.1步骤之后 注意项目工程为多个target的,Fastfile文件中的scheme参数确定配置正确。 5.3xcode手动打包没问题,但fastlane自动化打包报证书错误的,详细需要看终端提示Error Domain,仔细查看fastlane使用的哪个描述文件,该描述文件是否包含了相应证书。