打包开发总结

iOS项目自动打包

2018-05-14  本文已影响220人  翀鹰精灵

之前项目中使用的都是fir,为此,我还写过一篇fir的使用,但是最近在配置fir并使用的时候,发现提示fir即将过期,推荐使用Fastlane的gym来编译。为此,这里记录一下Fastlane的使用过程。

第一部分:Fastlane 安装篇

  1. 首先查看是否安装Ruby
allisondeMacBook-Pro:~ allison$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]

  1. 检测:确保已安装最新Xcode命令行工具
allisondeMacBook-Pro:~ allison$ xcode-select --install

如果未安装,终端会开始安装,如图1所示:


1.png

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

  1. 安装:安装fastlane命令行
allisondeMacBook-Pro:~ allison$ sudo gem install fastlane
Password:
Fetching: slack-notifier-2.3.2.gem (100%)
Successfully installed slack-notifier-2.3.2
Fetching: rouge-2.0.7.gem (100%)
......
Installing ri documentation for fastlane-2.95.0
55 gems installed

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

第二部分:使用篇

1)cd到自己的工程目录,然后执行fastlane init,会出现如下选项。

[14:48:40]: We recommend automating one task first, and then gradually automating more over time
[14:48:40]: 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
    ?

这四个选项的意思是
1.自动截屏。这个功能能帮我们自动截取APP中的截图,并添加手机边框(如果需要的话),我们这里不选择这个选项,因为我们的项目已经有图片了,不需要这里截屏。

2.自动发布beta版本用于TestFlight,如果大家有对TestFlight不了解的,可以参考王巍写的这篇文章

3.自动的App Store发布包。我们的目标是要提交审核到APP Store,按道理应该选这个,但这里我们先不选,因为选择了以后会需要输入用户名密码,以及下载meta信息,需要花费一定时间,这些数据我们可以后期进行配置。

4.手动设置。

这里我选择第四个,选择第四个后一路回车即可,我们会看到生成了我们fastlane目录的工程目录如下。(如果第一次操作,这个过程有些漫长,需要耐心等待)

2)初始化完成后,工程目录下回多出一个文件夹:fastlane,如图2

2.png
3)使用命令行安装蒲公英插件:fastlane add_plugin pgyer
allisondeMacBook-Pro:AutoPackingDemo allison$ fastlane add_plugin pgyer
[✔] 🚀 
[15:18:58]: fastlane detected a Gemfile in the current directory
[15:18:58]: however it seems like you don't use `bundle exec`
[15:18:58]: to launch fastlane faster, please use
......
Installing plugin dependencies...
Successfully installed plugins

4)打开其中的fastfile文件,进行配置

default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"
  lane :beta do
    # add actions here: https://docs.fastlane.tools/actions
      build_app(export_method: "ad-hoc")
      pgyer(api_key: "f4xxxxxxxxxxxxxxxxxxxxxx", user_key: "365xxxxxxxxxxxxxxxxxxxxxxx")
  end
end

tips:这里要正确填写自己蒲公英账号下的api_key和user_key.

5)打包并自动上传 App 到蒲公英
在终端下,定位到项目所在目录,输入以下命令即可:

allisondeMacBook-Pro:AutoPackingDemo allison$ fastlane beta

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


3.png
4.png
5.png

至此,蒲公英和本地都已经有IPA包了。

上一篇下一篇

猜你喜欢

热点阅读