fastlane自动化打包iOS APP过程示例

 更新时间:2022年07月20日 15:04:54   作者:QiShare  
这篇文章主要为大家介绍了fastlane自动化打包iOS APP的过程示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

概述

APP自动化打包常见的主流工具有JenkinsfastlaneJenkins功能强大,但是需要的配置也比较多,团队较大的可以优先考虑,fastlane是用Ruby语言编写的一套自动化工具集,比较轻便,配置简单,使用起来也很方便。本文会详细的介绍fastlane从安装到上传APP到蒲公英的整个流程。

fastlane的安装

第一步

因为fastlane是用Ruby语言编写的工具,所以必须保证已经配置好了Ruby开发环境。可以使用如下命令行查看是否安装了Ruby:

ruby -v

如果有以下提示说明,你已经安装了Ruby:

ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin21]

如果没有安装需要先安装ruby,本文对安装ruby不作教程说明。

第二步

安装Xcode命令行工具

xcode-select --install

如果没有安装,命令会有提示框,根据提示一步一步安装即可。 如果出现以下命令提示,说明已经安装成功:

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

第三步:

Ruby和Xcode环境都配置好之后,执行以下命令来安装fastlane:

sudo gem install -n /usr/local/bin fastlane

安装完成之后,输入以下命令查看是否安装成功:

fastlane --version

出现以下提示说明你已经安装成功了:

fastlane installation at path:
/Users/xxxxxx/.rvm/gems/ruby-2.7.0/gems/fastlane-2.206.1/bin/fastlane
-----------------------------
[✔] 🚀 
fastlane 2.206.1

fastlane的配置

到你的iOS项目下,执行初始化命令:

fastlane init

命令执行完成之后会给出我们如下几个提示:

[✔] 🚀 
[✔] Looking for iOS and Android projects in current directory...
[16:54:04]: Created new folder './fastlane'.
[16:54:04]: Detected an iOS/macOS project in the current directory: 'xxxx.xcworkspace'
[16:54:04]: -----------------------------
[16:54:04]: --- Welcome to fastlane 🚀 ---
[16:54:04]: -----------------------------
[16:54:04]: fastlane can help you with all kinds of automation for your mobile app
[16:54:04]: We recommend automating one task first, and then gradually automating more over time
[16:54:04]: 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
?  

命令执行到最后有What would you like to use fastlane for?提示,此时fastlane列出几个选项,需要我们告诉它使用fastlane需要执行哪种操作:

  • 第一种获取App Store的App预览照片。
  • 第二种打包上传至TestFlight工具上。
  • 第三种打包上传到App Store。
  • 第四种自定义打包方式。

以上四种方式根据自己的需要自行选择,本文主要介绍打包上传至第三方平台,所以选择4自定义打包方式。选择完成之后,fastlane会在我们项目中创建fastlane文件

[16:54:32]: ------------------------------------------------------------
[16:54:32]: --- Setting up fastlane so you can manually configure it ---
[16:54:32]: ------------------------------------------------------------
[16:54:32]: Installing dependencies for you...
[16:54:32]: $ bundle update
[16:54:40]: --------------------------------------------------------
[16:54:40]: --- ✅  Successfully generated fastlane configuration ---
[16:54:40]: --------------------------------------------------------
[16:54:40]: Generated Fastfile at path `./fastlane/Fastfile`
[16:54:40]: Generated Appfile at path `./fastlane/Appfile`
[16:54:40]: Gemfile and Gemfile.lock at path `Gemfile`
[16:54:40]: Please check the newly generated configuration files into git along with your project
[16:54:40]: This way everyone in your team can benefit from your fastlane setup
[16:54:40]: Continue by pressing Enter ⏎

创建好fastlane文件夹之后,Appfile是编辑我们相关App和开发者账号信息的,一般不需要我们去手动修改。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

打包并自动上传 App 到蒲公英

安装蒲公英的 fastlane 插件

fastlane add_plugin pgyer

编辑Fastlane 的配置文件 fastlane/Fastfile

lane :develop do
   target = "demo"
   configuration = "Debug"
   gym(scheme: target, configuration: configuration, export_method:"development")
   pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e")
end

以下是蒲公英平台的说明:

  • 以上的 api_keyuser_key,请开发者在自己账号下的 应用管理 - App概述 - API 中可以找到,并替换到以上相应的位置。
  • 在 Xcode 8.3 和 Xcode 8.3 以后的版本中,对于 build_appexport_method 的值,需要根据开发者的打包类型进行设置,可选的值有:app-storead-hocdevelopmententerprise。对于 Xcode 8.3 以下的版本,则不需要设置 export_method

经过以上配置后,就可以使用 Fastlane 来打包 App,并自动上传到蒲公英了。在终端下,定位到项目所在目录,输入以下命令即可:

fastlane develop

在成功的情况下,可以看到类似下面的信息:

[18:37:22]: Successfully exported and compressed dSYM file
[18:37:22]: Successfully exported and signed the ipa file:
[18:37:22]: /Users/xxx/Documents/workCode/xxxxx.ipa
[18:37:22]: -------------------
[18:37:22]: --- Step: pgyer ---
[18:37:22]: -------------------
[18:37:22]: The pgyer plugin is working.
[18:37:22]: build_file: /Users/dddd/Documents/workCode/xxxx.ipa
[18:37:22]: Start upload /Users/dddd/Documents/workCode/xxx.ipa to pgyer...
[18:37:43]: Upload success. Visit this URL to see: https://www.pgyer.com/xxxxx

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
| 2    | gym              | 61          |
| 3    | pgyer            | 20          |
+------+------------------+-------------+

[18:37:43]: fastlane.tools finished successfully 🎉

  • 设置一个版本更新时的描述信息:
lane :develop do
  build_app(export_method: "development")
  pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e", update_description: "update by fastlane")
end

打包上传到Testflight

在Fastfile文件中加入下面命令:

desc "打包上传到Testflight"
  lane :beta do
    # add actions here: https://docs.fastlane.tools/actions
   target = "demo"
   configuration = "Release"
   gym(scheme: target, configuration: configuration, export_method:"app-store")
   upload_to_testflight(
 	    username: "xxxx@dd.com",
            app_identifier: "com.xxxx",
          )

在命令行输入:

fastlane beta

打包上传的过程中会让你输入苹果账号的密码,并且有可能会报下面的错:

[00:20:28]: Login successful
[00:20:31]: Ready to upload new build to TestFlight (App: fffff)...
[00:20:40]: Transporter transfer failed.
[00:20:40]: 
[00:20:40]: Please sign in with an app-specific password. You can create one at appleid.apple.com. (-22910)
[00:20:41]: 
[00:20:41]: Your account has 2 step verification enabled
[00:20:41]: Please go to https://appleid.apple.com/account/manage
[00:20:41]: and generate an application specific password for
[00:20:41]: the iTunes Transporter, which is used to upload builds
[00:20:41]: 
[00:20:41]: To set the application specific password on a CI machine using
[00:20:41]: an environment variable, you can set the
[00:20:41]: FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD variable

这是因为你的APPLE账号开启了双重验证,注意这句提示Please sign in with an app-specific password用app专用密码登录,提示你创建一个app专用密码登录Transporter,关于怎么创建app专用密码本人不做讲解,可以自行百度或者谷歌,使用app专用账号即可解决此问题。

以上就是fastlane自动化打包iOS APP过程示例的详细内容,更多关于fastlane打包iOS APP的资料请关注脚本之家其它相关文章!

相关文章

  • Flutter Widgets粘合剂CustomScrollView NestedScrollView滚动控件

    Flutter Widgets粘合剂CustomScrollView NestedScrollVie

    这篇文章主要为大家介绍了Flutter Widgets粘合剂CustomScrollView NestedScrollView滚动控件示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-11-11
  • iOS应用设计模式开发中职责链(责任链)模式的实现解析

    iOS应用设计模式开发中职责链(责任链)模式的实现解析

    这篇文章主要介绍了iOS应用设计模式开发中职责链模式的相关实现解析,示例代码为传统的Objective-C,需要的朋友可以参考下
    2016-03-03
  • 解决iOS13 无法获取WiFi名称(SSID)问题

    解决iOS13 无法获取WiFi名称(SSID)问题

    这篇文章主要介绍了解决iOS13 无法获取WiFi名称(SSID)问题,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-09-09
  • iOS获取当前设备WiFi信息的方法

    iOS获取当前设备WiFi信息的方法

    很多公司现在都在做免费WIFI,车站、公交、地铁、餐厅,只要是人员密集流动的地方就有WIFI,免费WIFI从最初的网页认证方式也逐渐向客户端认证方式偏移。本文主要介绍iOS获取当前设备WiFi信息的方法,有需要的可以参考借鉴。
    2016-09-09
  • 在iOS中实现谷歌灭霸彩蛋的完整示例

    在iOS中实现谷歌灭霸彩蛋的完整示例

    这篇文章主要给大家介绍了关于如何在iOS中实现谷歌灭霸彩蛋的相关资料,文中通过示例代码介绍的非常详细,对各位iOS开发者们具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-05-05
  • 浅谈iOS11新特性:新增拖拽交互体验

    浅谈iOS11新特性:新增拖拽交互体验

    这篇文章主要介绍了浅谈iOS11新特性:新增拖拽交互体验,iOS11新引入了拖拽相关的API可以帮助开发者快速的构建拖拽交互,在iOS11中,使用这种API进行APP的开发为设计提供了一种全新维度的用户交互方式。
    2017-12-12
  • iOS实现圆角箭头视图

    iOS实现圆角箭头视图

    这篇文章主要为大家详细介绍了iOS实现圆角箭头视图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-04-04
  • iOS中valueForKeyPath的常用方法法示例

    iOS中valueForKeyPath的常用方法法示例

    这篇文章主要给大家介绍了关于iOS中valueForKeyPath的常用方法法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-07-07
  • Flutter之PageView页面缓存与KeepAlive

    Flutter之PageView页面缓存与KeepAlive

    这篇文章主要为大家介绍了Flutter之PageView页面缓存与KeepAlive示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-10-10
  • iOS整个APP实现灰色主题的示例代码

    iOS整个APP实现灰色主题的示例代码

    这篇文章主要介绍了iOS整个APP实现灰色主题的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02

最新评论