iOS📚苹果

iOS自动化构建 - fastlane集成

2022-02-17  本文已影响0人  鄭经仁

Fastlane是一套使用Ruby写的自动化工具集,旨在简化Android和iOS的部署过程,自动化你的工作流。它可以简化一些乏味、单调、重复的工作,像截图、代码签名以及发布App
一行命令实现打包工作,不需要时时等待操作下一步,节省打包的时间去做其他的事。

Fastlane的优势主要是下面几方面:

一、安装xcode命令行工具

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

二、安装Fastlane

终端执行sudo gem install fastlane -NV使用gem安装的或brew cask install fastlane安装完了终端执行fastlane --version,确认下是否安装完成和当前使用的版本号。
sudo gem install fastlane -NV
fastlane --version

三、初始化Fastlane

1.终端cd到你的项目目录执行,再执行fastlane init
cd [工程根目录]
fastlane init
执行fastlane init.png
2.这里会弹出四个选项,问你想要用Fastlane做什么? 之前的老版本是不用选择的。选几都行,后续我们自行根据需求完善就可以,直接选3执行
3.终端输入AppleID 账号和密码,选择对应的App Store Connect teams和Developer Portal
1.png
4.登录成功后会提示你是否需要下载你的App的metadata,输入y执行等待就可以,最终终端执行完毕之后返回bundle update,则表示成功下载
2.png
5.打开工程,在设置Current Project Version 设置1和 Versioning System设置Apple Generic
3.png
6.新开一个终端窗口,进入工程根目录,更新 bundle(会提示输入密码,这里输入开机密码)
cd [工程根目录]
bundle update
4.png
当返回Bundle updated!则表示bundle更新完成
7.到这一步前置配置全部完成

四、蒲公英 插件安装

1.进入工程根目录
cd [工程根目录]
2.安装蒲公英的 fastlane 插件
fastlane add_plugin pgyer
3.会询问fastlane 是否应该修改路径中的 Gemfile,输入y执行等待,当返回Successfully installed plugins,则表示安装插件成功
5.png

五、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 "用于发布到蒲公英"

  lane :adHoc do


#—————————————————————根据实际项目对应修改—————————————————————————
    #工程名称
    scheme = "xxxx" 
    bundleID = "xxxxx"

    #app名称
    appName = "xxxxx"
    
    #蒲公英获取key
    api_key = "xxxx"
    user_key = "xxxx"

    #蒲公英下载地址
    downloadURL = "xxxx"
#—————————————————————————————————————————————————————————————
    
    puts "*************| 开始上传蒲公英... |*************"

    #输入蒲公英上传ipa包后输入的版本描述信息
    puts "请输入版本描述:"
    descStr = STDIN.gets

    #指定打包环境 Debug、Test、Release、PreRelease
    puts "请指定需要打包的方式:1:Debug 2:Test 3:PreRelease 4:Release"
    configurationType = STDIN.gets
    if configurationType == "4\n"
      configurationName = "Release"
    elsif  configurationType == "3\n"
      configurationName = "PreRelease"
    elsif  configurationType == "2\n"
      configurationName = "Test"
    elsif  configurationType == "1\n"
      configurationName = "Debug"
    end

    #构建打包 也叫gym
    build_app(
      clean: true, #打包前clean 
      scheme: scheme, 
      workspace: "#{scheme}.xcworkspace", 
      export_method: "ad-hoc",
      include_bitcode: false,
      configuration: configurationName,#打包方式 
      output_directory: "./ipa", #导出路径 文件夹没有的话会自动新建一个
      silent: true, #在构建时隐藏终端不必要输出的信息
      output_name: "#{scheme}_#{Time.now.strftime('%Y%m%d%H%M')}.ipa"
    )

    pgyer(api_key: api_key, user_key: user_key, update_description: "更新内容:#{descStr}")
    notification(title: "提示", message: "#{appName} adHoc 打包成功: #{downloadURL}", open: downloadURL)

    puts "*************| 上传蒲公英成功🎉 |*************"
  end

end

六、打包到蒲公英

cd [工程根目录]
fastlane adHoc
6.png
上一篇 下一篇

猜你喜欢

热点阅读