今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

iOS 自动打包

iOS 自动打包#

使用 FastLane 打包#

安装 fastlane#

  • 通过 HomeBrew 安装
    brew install fastlane

  • 通过 Bundler 安装

    1. 安装 bundler
    2. 然后在项目根目录下创建./Gemfile 文件,编辑内容

// 安装 bundler
$ gem install bundler


//然后在项目根目录下创建./Gemfile文件,编辑内容
source "https://rubygems.org"
gem "fastlane"

编辑 Gemfile 文件:


source "https://rubygems.org"
gem "fastlane", "2.180.1"
# 如果使用Cocoapods,需要添加下面这行
gem "cocoapods"

  • 通过 ruby gems 安装
sudo gem install fastlane

fastlane 安装成功后,安装两个插件,用于版本号管理和打包成功后上传到对应的第三方平台

// 添加fastlane插件
// versioning使用参考,https://github.com/SiarheiFedartsou/fastlane-plugin-versioning,用于版本号获取和修改
// firim是fir平台插件

fastlane add_plugin versioning
fastlane add_plugin fir_cli # https://github.com/FIRHQ/fastlane-plugin-fir_cli


// pgyer是蒲公英平台
// fastlane add_plugin pgyer

fastlane 内容编辑#

fir 平台的 firim 相关参数参考:传送门,最少需要 firim_api_token 参数,可以从自己注册的 firim 中获取到,也可以配置如下参数

  • firim_api_token
  • app_name
  • app_desc
  • app_passwd
  • app_version
  • app_build_version
  • app_changelog
  • 等等

编辑 Fastfile,定义一个 Action,名字为 TestFir,指定输出包名为 (版本号 + 时间),打包后包到目录为./build 目录下,打包完成后上传到 fir。如下


default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"

  lane :TestFir do
    time = Time.new.strftime("%Y%m%d%H%M") # 获取时间格式,格式参考https://www.runoob.com/python/att-time-strftime.html
    # verion = get_version_number_from_list() # 获取版本号

    version = get_version_number_from_xcodeproj(build_configuration_name: 'Release') # 使用参考GitHub链接,https://github.com/SiarheiFedartsou/fastlane-plugin-versioning

    ipaName = "Release_#{version}_#time.ipa" # 生成ipa包的名字格式

    gym(
      clean: true, # 打包前清理项目
      silent: true, # 隐藏没有必要的信息
      scheme: "Your Scheme Name", # 指定项目的scheme名称
      export_method: "ad-hoc", # 打包的类型,有:ad-hoc, enterprise, app-store, development
      configuration: "Release", # scheme: 默认为Release,还有Debug
      output_name: "#{ipaName}", # 输出的报名
      output_directory: "./build" # 输出的位置
    )
    # 自己的fir账号,可配置内容参考https://github.com/FIRHQ/fastlane-plugin-fir_cli
    fir_cli api_token: "xxx",  changelog: "My First Fir Upload"
    # 蒲公英的配置 替换为自己的api_key和user_key
    # pgyer(api_key: "******", user_key: "******",update_description: options[:update_info])
  end

end

使用时,在命令行输入 fastlane TestFir 即可

fastlane TestFir

如果想要在执行命令时从外部传入参数,则可以按照下面的方式使用,在 do 后面添加 |options|,使用时,options [] 这种方式来获取从外面传入的值

lane :ActionName do |options|
    gym(
      configuration: options[:configuration],#环境
      )
    
    # 自己的fir账号
    fir_cli api_token: "xxx",  changelog: options[:changelog]
  end

从外面调用的方式如下:

fastlane ActionName configuration:"adhoc" changelog:"first submit"

使用 Jenkins 打包,未完待续#

参考#

iOS 之 自动打包 fastlane + fir + pgy 【进阶使用】

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。