Fastlane

fastlane是一个旨在简化 Android 和 iOS 布置的开源平台,能够主动化开发和发布工作流程的各个方面。

一、安装Xcode指令行东西

fastlane安装Xcode指令行东西:

xcode-select --install

Fastlane自动化打包到蒲公英
假如安装过会提示:

xcode-select: error: command line tools are already installed,
use "Software Update" in System Settings to install updates

二、安装fastlane

提早装备好HomeBrew管理东西

brew install fastlane

查看fastlane版别:

fastlane -v
fastlane installation at path:
/usr/local/Cellar/fastlane/2.206.2/libexec/gems/fastlane-2.206.2/bin/fastlane
-----------------------------
[✔] 
fastlane 2.206.2

将终端导航到项目目录并运转:

fastlane init

指令执行:

[✔] 
[13:13:34]: Sending anonymous analytics information
[13:13:34]: Learn more at https://docs.fastlane.tools/#metrics
[13:13:34]: No personal or sensitive data is sent.
[13:13:34]: You can disable this by adding `opt_out_usage` at the top of your Fastfile
[✔] Looking for iOS and Android projects in current directory...
[13:13:34]: Created new folder './fastlane'.
[13:13:34]: Detected an iOS/macOS project in the current directory: 'FastlaneDemo.xcodeproj'
[13:13:34]: -----------------------------
[13:13:34]: --- Welcome to fastlane  ---
[13:13:34]: -----------------------------
[13:13:34]: fastlane can help you with all kinds of automation for your mobile app
[13:13:34]: We recommend automating one task first, and then gradually automating more over time
[13:13:34]: 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

[13:13:34]你想用快车道做什么?

  1. 主动截屏
  2. ✈️主动测试分发TestFlight
  3. 主动化运用商铺分销
  4. 手动设置-手动设置您的项目主动化您的任务

这边选择4

[14:29:49]: --- Setting up fastlane so you can manually configure it ---
[14:29:49]: ------------------------------------------------------------
[14:29:49]: Installing dependencies for you...
[14:29:49]: $ bundle update
[14:31:36]: --------------------------------------------------------
[14:31:36]: --- ✅  Successfully generated fastlane configuration ---
[14:31:36]: --------------------------------------------------------
[14:31:36]: Generated Fastfile at path `./fastlane/Fastfile`
[14:31:36]: Generated Appfile at path `./fastlane/Appfile`
[14:31:36]: Gemfile and Gemfile.lock at path `Gemfile`

项目里多了这三个文件:

Fastlane自动化打包到蒲公英

三、安装蒲公英插件

fastlane add_plugin pgyer

注册蒲公英,拿到API KeyUser Key

Fastlane自动化打包到蒲公英

简略装备一下:

default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
# 打包时候用的名称   例如 fastlane app
lane :develop do |options|
target = "FastlaneDemo"
configuration = "Debug"
gym(scheme: target, configuration: configuration, export_method:"development")
pgyer(api_key: "xxxxxxxxxx”)
end
end

终端运转:

fastlane develop

结果:

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
| 2    | gym              | 78          |
+------+------------------+-------------+
[17:39:32]: fastlane.tools finished successfully 

能够看到上传蒲公英成功:

Fastlane自动化打包到蒲公英

点击运用信息:

Fastlane自动化打包到蒲公英

在项目本地也会生成一个ipa

Fastlane自动化打包到蒲公英

四、分发到Appstore

# 发布到appstore
  lane :to_appstore do
    # 先获取当时项目中的bundle version + 1
    @build_version = get_info_plist_value(path: "#{$info_plist_path}", key: "CFBundleVersion").to_i + 1
    # 针对于 iOS 项目开发证书和 Provision file 的下载东西
    sigh(
      force: true,
      output_path: "./fastlane/crets"
    )
    # 设置 bundle version
    set_info_plist_value(
      path: "./so/Supporting Files/so-Info.plist", 
      key: "CFBundleVersion", 
      value: "#{@build_version}"
    )
    # 针对于 iOS 编译打包生成 ipa 文件
    gym(
      workspace: "#{$project_name}.xcworkspace",
      scheme: "#{$project_name}",
      clean: true,
      configuration: "Release",
      export_method: "app-store",
      output_directory: "ipa_build/release",
      output_name: "#{$project_abbreviation}"
    )
    # 用于上传运用的二进制代码,运用截屏和元数据App Store
    deliver(
      force: true,# 上传之前是否成html报告
      submit_for_review: false,# 上传后主动提交审核
      automatic_release: true,# 通过审后主动发布
      skip_binary_upload: false,# 跳过上传二进制文件
      skip_screenshots: true,# 是否跳过上传截图
      skip_metadata: false,# 是否跳过元数据
    )
  end

运转:


[16:03:13]: $ bundle exec fastlane FastlaneDemo
[16:03:13]:
[16:03:13]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
+-----------------------+---------+--------+
|               Used plugins               |
+-----------------------+---------+--------+
| Plugin                | Version | Action |
+-----------------------+---------+--------+
| fastlane-plugin-pgyer | 0.2.4   | pgyer  |
+-----------------------+---------+--------+
[16:03:14]: ----------------------------------------
[16:03:14]: --- Step: Verifying fastlane version ---
[16:03:14]: ----------------------------------------
[16:03:14]: Your fastlane version 2.212.1 matches the minimum requirement of 2.68.2  ✅
[16:03:14]: ------------------------------
[16:03:14]: --- Step: default_platform ---
[16:03:14]: ------------------------------
[16:03:14]: Driving the lane 'ios FastlaneDemo' 
[16:03:14]: ----------------------------------
[16:03:14]: --- Step: get_info_plist_value ---
[16:03:14]: ----------------------------------
[16:03:14]: ------------------
[16:03:14]: --- Step: sigh ---
[16:03:14]: ------------------
+-------------------------------------+-------+
|          Summary for sigh 2.212.1           |
+-------------------------------------+-------+
| force                               | true  |
| adhoc                               | false |
| developer_id                        | false |
| development                         | false |
| skip_install                        | false |
| include_mac_in_profiles             | false |
| ignore_profiles_with_different_name | false |
| skip_fetch_profiles                 | false |
| include_all_certificates            | false |
| skip_certificate_verification       | false |
| platform                            | ios   |
| readonly                            | false |
| fail_on_name_taken                  | false |
+-------------------------------------+-------+
[16:03:14]: To not be asked about this value, you can specify 
it using 'username'
[16:03:14]: Your Apple ID Username:

输入Apple ID去测试 ……

参阅:

  • fastlane
  • 蒲公英官网文章
  • 运用Fastlane主动布置APP
  • fastlane + fir 主动化打包遇到的坑