您的当前位置:首页正文

iOS Fastlane 自动化打包初探

来源:华拓网

一、前言

fastlane.png

二、Fastlane 简介

三、环境搭建

  • 1、检查ruby版本 要求大于2.0.0
$ ruby -v
  • 2、检查 Xcode CLT 是否安装
$ xcode-select --install
  • 3、安装fastlane
$ gem install fastlane -NV

安装成功后就可以为项目配置fastlane 了

四、项目配置

  • 1、为项目配置 fastlane
$ cd 项目目录
$ fastlane init

初始化时,会出现4个选项:
Automate screenshots(自动化截图)
Automate beta distribution to TestFlight(TestFlight)
Automate App Store distribution (AppStore发布版本)
Manual setup - manually setup your project to automate your tasks(自定义)

直接输入1、2、3、4 选择你想创建的类型
中间会让输入苹果开发者账号和密码,之后会在你项目工程的目录下生成一个fastlane文件夹,里面有Fastlane的配置文件,一个是Appfile文件,一个是Fastfile文件(如果要上传AppStore的话还有Deliverfile文件)。

  • Appfile保存苹果开发者的相关信息、项目的相关信息等。
  • Fastfile是运行脚本。


    init

    生成的文件信息


    执行结束后产生的文件

五、上传蒲公英

  • 1、创建好faselane文件之后,安装蒲公英插件
//在项目目录下执行
$ fastlane add_plugin pgyer
  • 2、修改Fastfile 内容
    打开自动生成的Fastfile 我们可以看到
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

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 :beta do
  build_app(export_method: "ad-hoc")
  pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")
end
  • 3、打包并自动上传 App 到蒲公英
//在项目目录下执行
$ fastlane beta
执行结果

等待一段时间后上传蒲公英成功,大功告成!!!

六、 自定义lane,实现更多功能✨

default_platform(:ios)

platform :ios do 
  desc "上传蒲公英" 
  lane :beta do #beta 为lane 名称,我们执行时就是执行这个方法
 scheme_name = "TestDemo1" 

  #导出路径  我们可以桌面创建IPA_Info(没有的话会自动创建) 文件夹来集中管理生成的ipa等文件
  output_directory = "/Users/xxx/Desktop/IPA_Info"

  #导出名称 
  output_name = "#{scheme_name}_#{Time.now.strftime('%Y%m%d%H%M%S')}.ipa"
 
 gym(
    export_method: "ad-hoc", #这里填写导出方式 ad-hoc、enterprise、app-store  
   #Xcode 9 默认不允许访问钥匙串的内容,必须要设置此项才可以
    export_xcargs: "-allowProvisioningUpdates", 
    scheme: scheme_name,# target的名字
    clean: true, # 在构建前先clean
    output_directory: output_directory, #ipa输出目录
    output_name: output_name#ipa名字
) 
  # 上传蒲公英
  pgyer(api_key: "e4xxxxxxxd2863db4136227b2f3ba4", user_key: "5e50ae3a91xxxxxxx0bc62f1baa5f", update_description: "#{option[:desc]}") 
 end
end

// 在项目根目录执行
$ fastlane topgyer

gym部分参数

image.png

文章参考

  • 1、
  • 2、
  • 3、
  • 4、
  • 5、