Fastlane for iOS 介绍Introduction to fastlane for iOS

Fastlane 是一个开源项目,旨在简化 iOS 和 Android 应用混乱冗长的发布过程。fastlane is an open source project, created to simplify the confusing and often tedious process of releasing iOS and Android apps. 它包括的几个实用程序,每个实用程序负责处理应用发布的特定方面,例如:It comprises of several utilities that each handle a specific aspect of app release, such as:

  • Deliver – 管理屏幕快照、元数据和应用程序捆绑,并将其上传到 iTunes Connect。deliver – Manages and uploads screenshots, metadata, and application bundles to iTunes Connect.
  • Produce – 在 iTunes Connect 和开发人员门户(通常称为 AppID)中创建应用。produce – Creates and app in iTunes Connect and the Developer Portal (often known as AppID). 它还包括对应用组和应用程序服务的支持。It also includes support for App Groups and application services.
  • Pem – 创建和管理推送通知预配配置文件。pem – Creates and manages Push Notification Provisioning Profiles.
  • Gym – 可用于生成 iOS 应用程序并进行签名。gym – This can be used to build and sign an iOS application. (Xamarin 应用已使用 MSBuild 生成应用并进行签名和存档)(Xamarin apps already use MSBuild to build, sign, and archive apps)
  • Cert – 创建和管理代码签名证书cert – Creates and manages code signing certificates
  • Sigh – 创建和管理预配配置文件sigh – Creates and manages provisioning profiles
  • Match – 创建和维护证书和配置文件并将它们存储在 GIT 存储库中,以便它们可以跨开发团队同步。match – Creates and maintains certificates and profiles and stores them in a git repository so that they can be synced across a development team.

可以按以下不同的方式使用 Fastlane:通过终端命令、通过基于文件的方式,或通过将环境变量用于持续集成生成。fastlane can be used in different ways: through terminal commands, through file based means, or by using environment variables for continuous integration builds.

本指南专用于处理针对 iOS 应用开发的设备设置,重点介绍了 cert 、sigh 和 match 实用工具。This guide deals specifically with setting up a device for development with iOS apps, and focuses on the cert, sigh and match utilities.

提供的内容可用作帮助应用分发的 springboard,包括完全自动化持续集成服务器上的过程。The content provided can be used as a springboard to aid with app distribution, including fully automating the process on a continuous integration server. 但是,有必要记住 Fastlane 是生成 Xcode 项目支持工具的第三方,因此某些工具或命令(如 fastlane init)可能不会如期处理 csproj 文件。However, it's important to note that fastlane is a 3rd party who make tools to support Xcode projects and therefore some tools or commands such as fastlane init may not work as expected with csproj files. 有关使用 Fastlane 和其他工具或者有关使用 Fastlane 发布 Android 的详细信息,请参阅 https://fastlane.tools/For more information on using fastlane, additional tools, or releasing for Android using fastlane, refer to https://fastlane.tools/

安装Installation

  1. 请确保 macOS 计算机上安装了 Xcode 命令行工具。Make sure that Xcode command line tools are installed on the macOS machine. 若要安装工具,请在终端中使用命令 xcode-select --installTo install the tools, use the command xcode-select --install in Terminal. 如果已安装了这些工具,将显示以下错误:If they are already installed, the following error will be displayed:

    error: command line tools are already installed, use "Software Update" to install updates
    
  2. https://download.fastlane.tools 下载 Fastlane 工具。Download the fastlane tools from https://download.fastlane.tools.

    备注

    可以使用 brew cask install fastlane 从 Homebrew 安装 fastlane 工具,也可以使用 sudo gem install fastlane –NV 通过 Rubygems(2.0 或更高版本)安装。It is possible to install fastlane tools from Homebrew using brew cask install fastlane or via Rubygems (2.0 or above) using sudo gem install fastlane –NV. 但是,使用安全程序可以确保提供正确的依赖项。However using the installer will ensure that the correct dependencies are available.

  3. 通过解压缩文件安装 fastlane,然后双击 install 可执行文件。Install fastlane by unzipping the file, and double-click on the install executable. 如果收到错误通知“无法打开文件,因为它来自无法识别的开发人员”,请按“确定”,然后执行以下操作:If you get an error advising that the file "can't be opened because it is from an unidentified developer", press OK and do the following:

    • 按住 Ctrl 并单击 install 可执行文件。Control + Click on the install executable. 此时,将显示以下对话框:This will display the dialog below:

    • 按“确定”开始安装 fastlane 工具Press OK to start installing fastlane tools
  4. 终端将通过下面所示的对话框显示提示。Terminal will prompt you with the dialog illustrated below. yPress y:

  5. 首次使用 fastlane 之前,请运行 which fastlaneRun which fastlane before using fastlane for the first time. 路径应类似于:The path should look like the following:

    /Users/[user]/.fastlane/bin
    
  6. 如果路径与上述路径匹配,表明你已准备就绪。If the path matches the above, you're ready to get started.

    否则,请执行以下操作:在 macOS 上,使用以下命令打开 .bash_profile,这是一个主目录中隐藏的纯文本文件:If not, do the following: On macOS open .bash_profile, which is a hidden plaintext file in the home directory, with the following command:

    open ~/.bash_profile
    
  7. 添加下面的 PATH 环境变量并保存:Add the following PATH environment variable, and save it:

    export PATH="$HOME/.fastlane/bin:$PATH"
    
  8. 再次运行 which fastlane,以确认路径类似 /Users/[user]/.fastlane/binRun which fastlane again, to confirm the path looks like /Users/[user]/.fastlane/bin

更新 FastlaneUpdating fastlane

Fastlane 是一个非常活跃的开放源代码项目,会定期推出新版本。fastlane is a very active open source project that regularly pushes new releases. 当新版本的 Fastlane 可用时,将建议你运行 fastlane 命令的时间:When a new version of fastlane is available, you will be advised when you run any fastlane command:

若要更新为新版本的 fastlane,请从此处下载最新的包并双击安装包来运行它:To update to a new version of fastlane, download the latest package from here and double-click on the install package to run it:

内容Contents

本系列指南提供了一些工具,以供 fastlane 对 iOS 应用进行代码签名时使用,以做好开发或分发准备。This series of guides presents some of the tools that fastlane uses for code signing your iOS app in preparation for development or distribution. 目前介绍的这些工具有:The tools currently covered are:

Cert 和 Sigh 负责在本地计算机上创建和管理签名证书和预配配置文件。cert and sigh deal with creating and managing signing certificates and provisioning profiles on a local machine. Match 将此过程又更推进一步。match takes this process a step further. 它创建和管理证书和预配配置文件并将它们存储在 GIT 存储库,这样,开发团队的所有成员就可以访问它们。It creates and manages certificates and provisioning profiles, and stores them in a git repository, allowing them to be accessible by all members of a development team. 通读每个部分,找出它们的工作原理以及使用方法。Read through each section to find out how they work and how you can use them.

通过 Xamarin 使用 Fastlane 工具Using fastlane tools with Xamarin

利用 Fastlane 创建签名标识和预配配置文件之后,应可直接在 Visual Studio for Mac 中设置绑定签名选项,前提是证书和私钥都位于 macOS 密钥链中且预配配置文件位于文件夹 ~/Library/MobileDevice/Provisioning Profiles 中。Once you have created a signing identity and provisioning profiles with fastlane, setting the bundle signing options in Visual Studio for Mac should be straightforward, providing that the certificates and private keys are in the macOS Keychain and that provisioning profiles are in the folder ~/Library/MobileDevice/Provisioning Profiles.

若要设置 Xamarin.iOS 应用程序的代码签名选项,请右键单击项目名称,选择“项目选项”>“生成”>“iOS 捆绑签名” 显式设置签名标识和设预配配置文件,如下所示:To set the code signing options for a Xamarin.iOS application, right-click on the project name, select Project Options > Build > iOS Bundle Signing and set the Signing Identity and Provisioning Profile explicitly, as demonstrated below: