一 安装fastlane
sudo gem install fastlane --verbose
如果安装失败:
ERROR: While executing gem ... (TypeError)
no implicit conversion of nil into String
进行更新gem:
sudo gem update --system
安装成功:
➜ 1.0 fastlane -v
Ignoring bigdecimal-1.3.5 because its extensions are not built. Try: gem pristine bigdecimal --version 1.3.5
fastlane installation at path:
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.112.0/bin/fastlane
-----------------------------
[⠹] 🚀 Ignoring io-console-0.4.6 because its extensions are not built. Try: gem pristine io-console --version 0.4.6
Ignoring nokogiri-1.8.4 because its extensions are not built. Try: gem pristine nokogiri --version 1.8.4
Ignoring psych-3.0.2 because its extensions are not built. Try: gem pristine psych --version 3.0.2
Ignoring sqlite3-1.3.13 because its extensions are not built. Try: gem pristine sqlite3 --version 1.3.13
[✔] 🚀
fastlane 2.112.0
二 、项目初始化
fastlane init
**************** % fastlane init
[✔] 🚀
[✔] Looking for iOS and Android projects in current directory...
[11:14:47]: Created new folder './fastlane'.
[11:14:47]: Detected an iOS/macOS project in the current directory: '调机软件.xcworkspace'
[11:14:47]: -----------------------------
[11:14:47]: --- Welcome to fastlane 🚀 ---
[11:14:47]: -----------------------------
[11:14:47]: fastlane can help you with all kinds of automation for your mobile app
[11:14:47]: We recommend automating one task first, and then gradually automating more over time
[11:14:47]: 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. 手动设置
直接选择第4个对其进行手动配置后进入:
[15:17:15]: ------------------------------------------------------------
[15:17:15]: --- Setting up fastlane so you can manually configure it ---
[15:17:15]: ------------------------------------------------------------
[15:17:15]: Installing dependencies for you...
[15:17:15]: $ bundle update
其他命令:
fastlane actions: 列出所有可用fastlane活动
fastlane action [action_name]: 显示一个更详细的活动描述
fastlane lanes: 列出所有可用lanes (有描述)
fastlane list: 列出所有可用lanes (没有描述)
fastlane new_action: 在fastlane创建一个活动(集成)
三、对fastlane 文件的认识:
现在对Appfile,Fastfile,Gemfile,Deliverfile文件说明如下:
Appfile: 存储有关开发者账号相关信息
Fastfile: 核心文件,用于命令行调用和处理具体的流程,lane相对于一个action方法或函数
Gemfile 类似于cocopods 的Podfile文件
.env 配置环境变量(在fastlane init进行初始化后并不会自动生成,如果需要可以自己创建
Deliverfile: deliver工具的配置文件,上传截图苹果和后台一些app信息 (默认不生成,需要sudo gem install deliver安装)然后在fastlane 目录下执行deliver init 即可)
要注意的点:
build_app命令等同于gym(别名)
deliver 命令相当于upload_to_app_store(别名)
四、添加插件
列出所有的插件
fastlane search_plugins
搜索指定名称的插件
fastlane search_plugins [query]
添加插件
fastlane add_plugin [name]
安装插件
fastlane install_plugins
添加蒲公英插件
fastlane add_plugin pgyer
fastlane add_plugin versioning
添加match全家桶
fastlane match init
五、配置相关文件信息
配置主文件:Fastfile
配置证书的存放路径
Appfile文件代码如下:
app_identifier("com.****.****") # The bundle identifier of your app
apple_id("********@qq.com") # Your Apple email address
itc_team_id("*******") # App Store Connect Team ID
team_id("*******") # Developer Portal Team ID
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
#--发布蒲公英上的版本配置
for_lane :pgy do
app_identifier "com.*******.cn" # The bundle identifier of your app
apple_id "*************@163.com" # Your Apple email address
end
Fastfile文件文件代码如下:
定义打包平台
default_platform :ios
platform :ios do
before_all do
git_pull
last_git_commit
sh "rm -f ./Podfile.lock"
cocoapods(use_bundle_exec: false)
end
运行所有的测试
lane :test do
scan
end
提交一个新的Beta版本
确保配置文件是最新的
lane :beta do
gym
pilot
end
将新版本部署到应用程序商店
lane :release do
gym
deliver(force: true)
end
以下是发布版本的配置
lane :pgy do
sigh(
app_identifier: "com.zidongdabao.cn" #项目的bundle identifler
)
开始打包
# 定义打包平台
default_platform :ios
platform :ios do
before_all do
git_pull
last_git_commit
sh "rm -f ./Podfile.lock"
cocoapods(use_bundle_exec: false)
end
# 运行所有的测试
lane :test do
scan
end
# 提交一个新的Beta版本
# 确保配置文件是最新的
lane :beta do
gym
pilot
end
# 将新版本部署到应用程序商店
lane :release do
gym
deliver(force: true)
end
# 以下是发布版本的配置
lane :pgy do
sigh(
app_identifier: "com.zidongdabao.cn" #项目的bundle identifler
)
# 开始打包
gym(
scheme: “Fastlane--Packaging”, #指定项目的scheme名称
configuration: "Release", # 指定打包方式,Release 或者 Debug
silent: true, # 隐藏没有必要的信息
clean: true, # 是否清空以前的编译信息 true:是
workspace: "Fastlane--Packaging.xcworkspace",
include_bitcode: false, #项目中的bitcode 设置
output_directory: './pgy', # 指定输出文件夹
output_name: "Fastlane--Packaging.ipa", #输出的ipa名称
export_xcargs: "-allowProvisioningUpdates”, #忽略文件
)
# 开始上传蒲公英
pgyer(api_key: "1303c11160b475cc56b9d5df820a17ed", user_key: "dd705842c35567b3f2620e6a047024f0")
end
end
4.在终端执行自动打包
在终端输入
fastlane ios
fatlane --命令说明
* scan -- 自动运行测试工具,并且可以生成漂亮的HTML报告
- cert -- 自动创建管理iOS代码签名证书
* sigh -- 一声叹息啊,这么多年和Provisioning Profile战斗过无数次。总是有这样那样的问题导致配置文件过期或者失效。sigh是用来创建、更新、下载、 修复Provisioning Profile的工具。
- pem -- 自动生成、更新推送配置文件
* match -- 一个新的证书和配置文件管理工具。我会另写一篇文章专门介绍这个工具。他会所有需要用到的证书传到git私有库上,任何需要配置的机器直接用match同步回来就不用管证书问题了,小团队福音啊! * gym -- Fastlane家族的自动化编译工具,和其他工具配合的非常默契
- produce -- 如果你的产品还没在iTunes Connect(iTC)或者Apple Developer Center(ADC)建立,produce可以自动帮你完成这些工作
* deliver -- 自动上传截图,APP的元数据,二进制(ipa)文件到iTunes Connect
- pilot -- 管理TestFlight的测试用户,上传二进制文件
六、遇到问题
出现错误:
[17:13:49]: ▸ ** ARCHIVE SUCCEEDED **
[17:13:49]:
[17:13:49]: ⬆️ Check out the few lines of raw `xcodebuild` output above for potential hints on how to solve this error
[17:13:49]: 📋 For the complete and more detailed error log, check the full log at:
[17:13:49]: 📋 /Users/liujingxu/Library/Logs/gym/M-Pay-M-Pay.log
[17:13:49]:
[17:13:49]: Looks like fastlane ran into a build/archive error with your project
[17:13:49]: It's hard to tell what's causing the error, so we wrote some guides on how
[17:13:49]: to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[17:13:49]: Before submitting an issue on GitHub, please follow the guide above and make
[17:13:49]: sure your project is set up correctly.
[17:13:49]: fastlane uses `xcodebuild` commands to generate your binary, you can see the
[17:13:49]: the full commands printed out in yellow in the above log.
[17:13:49]: Make sure to inspect the output above, as usually you'll find more error information there
[17:13:49]:
[17:13:49]: Looks like no provisioning profile mapping was provided
[17:13:49]: Please check the complete output, in particular the very top
[17:13:49]: and see if you can find more information. You can also run fastlane
[17:13:49]: with the `--verbose` flag.
[17:13:49]: Alternatively you can provide the provisioning profile mapping manually
[17:13:49]: https://docs.fastlane.tools/codesigning/xcode-project/#xcode-9-and-up
+------------------+---------------+
| Lane Context |
+------------------+---------------+
| DEFAULT_PLATFORM | ios |
| PLATFORM_NAME | ios |
| LANE_NAME | ios adhoc_pgy |
| BUILD_NUMBER | 2 |
+------------------+---------------+
[17:13:49]: Error packaging up the application
+------+------------------------+-------------+
| fastlane summary |
+------+------------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------------+-------------+
| 1 | default_platform | 0 |
| 2 | cocoapods | 3 |
| 3 | increment_build_numbe | 1 |
| | r | |
| 💥 | build_app | 84 |
+------+------------------------+-------------+
[17:13:49]: fastlane finished with errors
[!] Error packaging up the application
match文件配置
- 首页需要一个git仓库用来存放Cer证书
- git 仓库需要添加ssh公钥
生产密钥:ssh-keygen
查看密钥:cat ~/.ssh/id_rsa.pub
2、错误信息
[16:19:23]: URL to the git repo containing all the certificates: https://gitee.com/mxlj/M-Pay-Cer.git
[16:19:33]: Cloning remote git repo...
[16:19:33]: If cloning the repo takes too long, you can use the `clone_branch_directly` option in match.
Cloning into '/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2'...
fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
[16:19:34]: Exit status: 128
[16:19:34]: Error cloning certificates repo, please make sure you have read access to the repository you want to use
[16:19:34]: Run the following command manually to make sure you're properly authenticated:
[16:19:34]: $ git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/d20190409-13299-1p3m5n2
[!] Error cloning certificates git repo, please make sure you have access to the repository - see instructions above
解决方法:
注:出现这个问题是因为mac git终端没有读写的权限,问题。
未找到修改权限的方法来解决此问题,所有使用下面的方面来解决。
运行:
git clone https://gitee.com/mxlj/M-Pay-Cer.git /var/folders/xc/bzrxbntn1fq_fw53ks0_jbzc0000gn/T/d20190409-13848-156jw68
修改Fastlane文件的scheme:为项目名称
报satus 70错误
** EXPORT FAILED **
[17:28:29]: Exit status: 70
解决办法:
把xcode证书自动管理修改为手段管理,就可以解决此问题。
网友评论