iOS中使用Fastlane实现自动化打包和发布

2017-05-19 14:46 编辑: sasukeo 分类:iOS开发 来源:iOS_小松哥的简书

1 1241

iOS开发自动化fastlane

招聘信息:
  • Cocos2d-x js高级开发工程师
  • Mac开发
  • 应用开发工程师(iOS)
  • 技术合伙人-后端工程师
  • 高级iOS开发工程师
  • 资深软件研发工程师
  • 嵌入式软件工程师
  • 产品经理
  • cocos2d-x休闲游戏开发
  • Cocos2d-x游戏客户端开发
  • Java工程师
 

简介

Fastlane是一套使用Ruby写的自动化工具集,用于iOS和Android的自动化打包、发布等工作,可以节省大量的时间。

Fastlane

Github:https://github.com/fastlane/fastlane

官网:https://fastlane.tools/

文档:https://docs.fastlane.tools/

在写这篇文章的时候,他在Github上已经有15000+ star。

安装

1、首先要安装正确的 Ruby 版本。在终端窗口中用下列命令来确认:

1
ruby -v

2、然后检查 Xcode 命令行工具是否安装。在终端窗口中输入命令:

1
xcode-select --install

如果未安装,终端会开始安装,如果报错误:command line tools are already installed, use "Software Update" to install updates.代表已经安装。

3、以上依赖配置好之后就可以通过 rubygem 进行安装了:

1
$ sudo gem install fastlane

安心等待一会,fastlane就安装完成了。

初始化

打开终端,cd到你的工程目录,然后执行fastlane init:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$ cd to/your/ios/project 
$ fastlane init
[14:21:43]: Detected iOS/Mac project in current directory...
[14:21:43]: This setup will help you get up and running in no time.
[14:21:43]: fastlane will check what tools you're already using and set up
[14:21:43]: the tool automatically for you. Have fun! 
[14:21:43]: Created new folder './fastlane'.
[14:21:43]: $ xcodebuild -showBuildSettings -project ./xxx.xcodeproj
[14:21:48]: Your Apple ID (e.g. fastlane@krausefx.com): xxx@xxx.xom
[14:21:54]: Verifying that app is available on the Apple Developer Portal and iTunes Connect...
[14:21:54]: Starting login with user 'xxx@xxx.com'
+----------------+--------------------------------------+
|                    Detected Values                    |
+----------------+--------------------------------------+
| Apple ID       | xxx@xxx.com                    |
| App Name       | xxx                            |
| App Identifier | com.xxx.xxx                |
| Project        | /Users/lisong/Desktop/xxx/x  |
|                | xx.xcodeproj                     |
+----------------+--------------------------------------+
[14:22:06]: Please confirm the above values (y/n)
y
[14:22:09]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
[14:22:09]: Loading up 'deliver'this might take a few seconds
[14:22:09]: Login to iTunes Connect (xxx@xxx.com)
[14:22:13]: Login successful
+-----------------------+------------------------+
|             deliver 2.30.1 Summary             |
+-----------------------+------------------------+
| screenshots_path      | ./fastlane/screenshots |
| metadata_path         | ./fastlane/metadata    |
| username              | xxx@xxx.com      |
| app_identifier        | com.xxx.xxx  |
| edit_live             | false                  |
| platform              | ios                    |
| skip_binary_upload    | false                  |
| skip_screenshots      | false                  |
| skip_metadata         | false                  |
| force                 | false                  |
| submit_for_review     | false                  |
| automatic_release     | false                  |
| dev_portal_team_id    | WKR87TTKML             |
| overwrite_screenshots | false                  |
+-----------------------+------------------------+
[14:22:21]: Writing to 'fastlane/metadata/zh-Hans/description.txt'
...
[14:22:21]: Writing to 'fastlane/metadata/review_information/notes.txt'
[14:22:21]: Successfully created new configuration files.
[14:22:22]: Successfully downloaded large app icon
[14:22:22]: Downloading all existing screenshots...
[14:22:27]: Downloading existing screenshot '1_iphone4_1.1.jpg' for language 'zh-Hans'
···
[14:22:34]: Downloading existing screenshot '5_iphone6_5.5.jpg' for language 'zh-Hans'
[14:22:34]: Successfully downloaded all existing screenshots
[14:22:34]: Successfully created new Deliverfile at path 'fastlane/Deliverfile'
[14:22:34]: $ xcodebuild -list -project ./xxx.xcodeproj
[14:22:35]: 'snapshot' not enabled.
[14:22:35]: 'cocoapods' enabled.
[14:22:35]: 'carthage' not enabled.
[14:22:35]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[14:22:35]: fastlane will collect the number of errors for each action to detect integration issues
[14:22:35]: No sensitive/private information will be uploaded
[14:22:35]: Learn more at https://github.com/fastlane/fastlane#metrics
[14:22:35]: Successfully finished setting up fastlane

在 "Your Apple ID" 这一步输入苹果开发者账号。在“Please confirm the above values”这一步,确认信息,没问题输入 y。然后,fastlane 会进行一系列的初始化操作,包括下载 App Store 上的元数据和截屏文件。

等待初始化完成之后,工程目录下就多了一个 fastlane目录,其内容如下:

fastlane目录

咱们来看两个主要的,Appfile和Fastfile。

Appfile

Appfile用来存放app_identifier,apple_id和team_id。 了解详情,它的格式是这样的:

1
2
3
4
5
app_identifier "com.xxx.xxx" # app的bundle identifier
apple_id "xxx@xxx.com" # 你的Apple ID
team_id "XXXXXXXXXX" # Team ID
···

你也可以为每个lane(后面会讲到)提供不同的 app_identifier, apple_id 和 team_id,例如:

1
2
3
4
5
6
7
8
9
app_identifier "com.aaa.aaa"
apple_id "aaa@aaa.com"
team_id "AAAAAAAAAA"
for_lane :inhouse do
  app_identifier "com.bbb.bbb"
  apple_id "bbb@bbb.com"
  team_id "AAAAAAAAAA"
end

这里就是为Fastfile中定义的:inhouse设置单独的信息。

Fastfile

Fastfile管理你所创建的 lane ,了解详情。它的格式是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
···
# 自动更新fastlane 工具
# update_fastlane
#需要的fastlane的最小版本,在每次执行之后会检查是否有新版本,如果有会在最后末尾追加新版本提醒
fastlane_version "2.30.1"
#默认使用平台是 ios,也就是说文件可以定义多个平台
default_platform :ios
platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    cocoapods
  end
  desc "Runs all the tests"
  lane :test do
    scan
  end
  desc "提交一个新的Beta版本到 Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    gym(scheme: "Docment"# Build your app - more options available
    pilot
    # sh "your_script.sh"
  end
  desc "部署一个新版本到App Store"
  lane :release do
    # match(type: "appstore")
    # snapshot
    gym(scheme: "Docment"# Build your app - more options available
    deliver(force: true)
    # frameit
  end
  # 你可以定义自己的lane
  #执行lane成功后的回调
  after_all do |lane|
    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end
  # 如果流程发生异常会走这里并终止
  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end

我们也可以定义一个自己的lane:

1
2
3
4
5
6
7
8
  desc "企业版"
  lane :inHouse do
  gym(scheme: "XXX",
      export_method:"enterprise",
      output_directory "./build"# 打包后的 ipa 文件存放的目录
      output_name "XXX"  # ipa 文件名
   )
  end

其中一个lane就是一个任务,里面是一个个的action组成的工作流。

利用目前支持的工具可以做所有包含自动化和可持续化构建的每个环节,例如:

  • scan 自动化测试工具,很好的封装了 Unit Test

  • sigh 针对于 iOS 项目开发证书和 Provision file 的下载工具

  • match 同步团队每个人的证书和 Provision file 的超赞工具

  • gym 针对于 iOS 编译打包生成 ipa 文件

  • deliver 用于上传应用的二进制代码,应用截屏和元数据到 App Store

  • snapshot 可以自动化iOS应用在每个设备上的本地化截屏过程

执行

定义完lane之后怎么执行呢?打开终端,切换到项目的根目录:执行fastlane lane'name就可以了。成功之后会在相应的路径下生成ipa文件,如果报错的话就根据错误信息好好查看文档。

其他

1、这里是官方提供的一些例子。

2、想了解fastlane命令的话可以执行$ fastlane --help

3、查看可用任务的列表,可以执行命令$ fastlane lanes

4、fastlane也提供了很多插件方便我们使用,例如pgyer(发布app到蒲公英)。我们也可以打完包直接传到蒲公英上,具体的可以看蒲公英提供的文档。

如果你感觉有些插件不符合自己的情况,你甚至可以自定义插件

5、多个 lane 的话实际上是可以相互调用的,这个其实特别实用。例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
default_platform :ios
platform :ios do
  lane :prepare do
    cocoapods
    match
  end
  desc 'fastlane build'   'fastlane build type:adhoc'
  lane :build do |options|
    # 调用上面的 prepare 任务
    prepare
    case options[:type]
    when 'adhoc'
      adhoc
    else
      appstore
    end
  end
  lane : adhoc do
  ···
  end
  lane : appstore do
  ···
  end
end

6、我们可以在 Fastfile 文件中添加一个函数来设置version号和build号。

1
2
3
4
5
6
7
8
9
10
11
default_platform :ios
def prepare_version(options)
    increment_version_number(
        version_number: options[:version]
    )
    increment_build_number(
        build_number: options[:build]
    )
end

然后可以在一个lane中使用这个函数:

1
2
3
4
5
lane :appstore do |options|
   ···
    prepare_version(options)
   ···
end

然后执行这个lane的时候:

1
$ fastlane appstore version:2.4.0 build:2.0

好啦,先说到这里吧,Fastlane能做的事情还有很多,大家可以去好好看看文档,研究一些高级的用法吧!

欢迎关注 我 和我的专题:iOS技术交流,查看更多好文章。

iOS中使用Fastlane实现自动化打包和发布相关推荐

  1. iOS自动化探索(九)使用Jenkins自动化打包并发布iOS App

    继前一篇: Mac环境下安装Jenkins Jenkins安装好后, 我们试着创建一个iOS自动打包并发布的任务 iOS App构建必须在MAC上面使用xcode进行,所以我们要安装下xcode集成插 ...

  2. Python3自动化打包项目发布到pypi

    效果 D:\Program\Python310\python.exe D:\data\git\PythonLinuxBasicModule\upload.py C:\Users\刘某 usage: t ...

  3. 关于fastlane自动化打包

    fastlane(自动化打包) 安装: sudo gem install -n /usr/local/bin fastlane 复制代码 1.在工程目录下,会在工程下生成fastlane文件夹 fas ...

  4. ios html gif 显示,iOS中gif图的显示方法示例

    iOS中gif图的显示方法示例 发布时间:2020-09-19 06:15:42 来源:脚本之家 阅读:86 作者:蓝光95 一.前言 iOS开发中,大部分时候我们显示一张静态图就可以了,但是有的时候 ...

  5. iOS自动化打包发布之fastlane 实现 发布AppStore 蒲公英

    iOS自动化打包发布之fastlane 实现 fastlane官方文档 前提插件配置 首先要安装xcode-select 然后安装fastlane sudo gem install fastlane ...

  6. iOS自动化打包发布(fastlane)

    一.FastLane介绍 1.1 FastLane是什么? FastLane是一种配置iOS和Android自动化Beta部署和发布的最简单的方法之一.它可以简化一些乏味.单调.重复的工作,像截图.代 ...

  7. iOS开发之fastlane自动化打包工具安装和使用

    fastlane的文档:https://docs.fastlane.tools/ fastlane介绍: fastlane是用Ruby语言编写的一套自动化工具集和框架,每一个工具实际都对应一个Ruby ...

  8. Xcode + cocoapods + jenkins + fastlane + git + 蒲公英自动化打包 上传

    Xcode + cocoapods + jenkins + fastlane + git + 蒲公英自动化打包 上传 构建自动化步骤为: 1. Xcode 有Xcode 内部提供的打包命令来打包完成代 ...

  9. xcode 选择configuraftions 打包_分利宝IOS自动化打包

    前言 在iOS开发中,我们常用的打包上传方式就是用Xcode的archive方式打包.到了测试阶段,需要频繁的打包提交到测试平台,整个流程包括:编译-打包-上传,整个过程需要我们去坚守每一步操作,提交 ...

最新文章

  1. MATLAB对比度调节工具
  2. Android开发--实现对话框(AlertDialog)
  3. 关于谷歌地图无法获取到WebGL上下文问题
  4. Oulipo (KMP出现次数)
  5. delphi mysql 图片_delphi数据库图片的存取 【转】
  6. php 中的关联数组 介绍
  7. 塞班S40手机内存出现乱码无法删除的解决办法
  8. 通过AWS了解云计算系列——云计算的核心技术体系
  9. 正确的座机号码格式_国际标准电话号码格式
  10. Excel函数 - Round函数使用方法
  11. python c语言实现_使用C语言为python编写动态模块(3)--在C中实现python中的类
  12. 【牛腩新闻发布系统之handler】
  13. plotjuggler⬅ROS1/ROS2画轨迹神器➡rqt_plot+rqt_multiplot之超级加强版
  14. 怎么撰写一份优秀的数据分析报告(三)
  15. matlab双曲函数
  16. Python3,10行代码,制作艺术签名,从此走上人生巅峰。
  17. AI厂工什么时候开始赛博搬砖?
  18. 设计模式:工厂方法与抽象工厂模式
  19. python中ctypes的使用
  20. ppt里面怎么打破折号

热门文章

  1. Photoshop期末大作业
  2. python查看源代码
  3. Python之正则表达式小练
  4. 非财务人员财务培训_为非财务领导的公司工作
  5. 其实数据科学跟烹饪很相似
  6. 读《曾国藩》中义理之学的感悟
  7. 计算机学科各专业大牛
  8. React 笔记--FAQ
  9. linux系统core dump设置,Linux 下生成 core dump 配置和用法
  10. 3月30日—4月3日四年级课程表