一、前置条件
1.通过下面命令查看本机ruby版本,没有需要安装
ruby --version
2.安装Xcode命令行工具
xcode-select –install
二、安装fastlane
1.执行下面命令安装fastlane
sudo gem install fastlane
2.检查是否安装正确
fastlane --version
三、初始化一个fastlane
1.cd到你的工程目录。cd到你的工程目录。cd到你的工程目录。重要的事情说三遍。
2.执行下面命令
fastlane init
3.初始化的过程中会出现下面的选项:

其中对应如下图
-1. 自动截屏。
-2. 自动发布beta版本用于TestFlight
-3. 自动的App Store发布包。
-4. 手动设置。
我此处选择了4手动配置,命令继续执行
4.如果fastlane init卡在了bundle update处,请看第5步。如果顺利没卡住,请看第6步。

5.bundle update很慢的解决方案
5.1关闭终端
5.2打开项目文件夹,找到fastlane init过程中生成的Gemfile文件,并打开(Gemfile文件就在你项目目录下)
Gemfile部分内容一般如下,我们需要将source源修改,不然被墙很难成功
source "https://rubygems.org"
gem "fastlane"
修改如下
source "https://gems.ruby-china.com"
gem "fastlane"
当然,你也可以换成其他可执行的ruby源。
5.3打开终端,cd到当前项目,执行bundle update命令
bundle update
6.fastlane init成功会在项目目录下生成fastlane文件夹,以及Appfile和Fastfile两个文件

7.配置Appfile和Fastfile。注意通过终端使用 vim命令来修改这俩文件,不可打开修改。
Appfile修改内容如下。你需要替换app_identifier、apple_id、team_id为你自己的东西,其中apple_id、team_id可以在开发者网站上找到。
# app_identifier("你的项目identifier") # The bundle identifier of your app
# apple_id("你的开发者账号的邮箱") # Your Apple email address
# team_id("你的开发者账号的team_id")
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
Fastfile修改内容如下。你需要替换api_key和user_key为你自己的东西。api_key和user_key都在蒲公英账户信息里可以查到。
# 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
build_app(export_method: "ad-hoc")
pgyer(api_key: "蒲公英分配的api_key", user_key: "蒲公英分配的user_key")
end
end
四、配置蒲公英插件
1. cd到工程目录下,安装蒲公英插件。插件安装好后,工程的fastlane目录下会多出 Gemfile、Gemfile.lock 、Plugfile这三个文件。
fastlane add_plugin pgyer
五、打包上传到蒲公英
1. cd到工程目录下,执行下面命令(注意,custom_lane为Fastfile文件里的 lane :custom_lane do中间的custom_lane。如果此处你写什么你就把下面命令替换为什么。比如你写的是lane :test do,那么就执行 fastlane test )
fastlane custom_lane
2. 等到出现下图后,就可以去蒲公英上查看最新的打包二维码了。

六、错误处理
如果出现 PGYER Plugin Error: ,那是因为蒲公英平台安装APP是需要密码,如下更改配置就行
之前的配置
pgyer(api_key: "6xxxxxxxxxxxxxxxxxx", user_key: "3xxxxxxxxxxxxxx")
更改之后的
pgyer(api_key: "6xxxxxxxxxxxxxxxxxx", user_key: "3xxxxxxxxxxxxxx", password: "111111", install_type: "2")
增加之后的password测试人员需要输入这个才能下载,比如此处下载密码为111111
如果刚安装好环境,第一次使用fastlane自动打包时或之后打包出现如下错误,说明证书的关联没有找到或者失效。需要手动打包一次触发证书的关联(手动点击xcode的Archive打包)。
Exit status: 70
网友评论