你是否还在忍受打包时电脑风扇嗡嗡作响的苦恼, 还在"享受"MacOS菊花转起来的微妙, 是否陷入了jenkins的泥沼中止步不前? -- fastlane, (私认为)一款市面上最好的打包分发工具, 足以带你脱离苦海.
Why fastlane?
fastlane | |
---|---|
🚀 | 每次发包, 省时省力 |
✨ | 方便的集成你先有的工具和服务, 同时自己囊括了400多个工具. |
📖 | 基于MIT开源 |
🎩 | 几分钟之内就可以部署 |
⚒ | 在你自己的机器上运行. |
👻 | 集成了所有的CI系统. |
🖥 | 支持iOS、 MacOS、 Android app. |
🔧 | 基于需求 自行扩展, 不需要依赖任何东西. |
💭 | 一行fastlane走天下, 其他指令全都不需要. |
🚢 | 可在其他任何设备甚至是CI服务上部署. |
开始搭建
具体的搭建可以参考官方文档, https://docs.fastlane.tools/,
本篇只记录一些细节坑点.
选择模式时选中3
, 这样会走拉取iTunes Connect
中 app信息的流程.
[11:39:03]: 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
此时询问你是否允许 fastlane来管理你iTunes Connect app的元数据, 包括一些 app描述, 关键词, 以及截图等等. 建议允许
[11:43:52]: Would you like to have fastlane manage your app's metadata?
[11:43:52]: If you enable this feature, fastlane will download your existing metadata and screenshots.
[11:43:52]: This way, you'll be able to edit your app's metadata in local `.txt` files.
[11:43:52]: After editing the local `.txt` files, just run fastlane and all changes will be pushed up.
[11:43:52]: If you don't want to use this feature, you can still use fastlane to upload and distribute new builds to the App Store
[11:43:52]: Would you like fastlane to manage your app's metadata? (y/n)
执行完这些步骤之后, 就会发现项目目录下产生了一个fastlane的文件夹, 里面的结构是这样的:
.
├── Appfile
├── Deliverfile
├── Fastfile
├── metadata
│ ├── app_icon.jpg
│ ├── copyright.txt
│ ├── primary_category.txt
│ ├── primary_first_sub_category.txt
│ ├── primary_second_sub_category.txt
│ ├── review_information
│ │ ├── demo_password.txt
│ │ ├── demo_user.txt
│ │ ├── email_address.txt
│ │ ├── first_name.txt
│ │ ├── last_name.txt
│ │ ├── notes.txt
│ │ └── phone_number.txt
│ ├── secondary_category.txt
│ ├── secondary_first_sub_category.txt
│ ├── secondary_second_sub_category.txt
│ ├── trade_representative_contact_information
│ │ ├── address_line1.txt
│ │ ├── address_line2.txt
│ │ ├── address_line3.txt
│ │ ├── city_name.txt
│ │ ├── country.txt
│ │ ├── email_address.txt
│ │ ├── first_name.txt
│ │ ├── is_displayed_on_app_store.txt
│ │ ├── last_name.txt
│ │ ├── phone_number.txt
│ │ ├── postal_code.txt
│ │ ├── state.txt
│ │ └── trade_name.txt
│ └── zh-Hans
│ ├── apple_tv_privacy_policy.txt
│ ├── description.txt
│ ├── keywords.txt
│ ├── marketing_url.txt
│ ├── name.txt
│ ├── privacy_url.txt
│ ├── promotional_text.txt
│ ├── release_notes.txt
│ ├── subtitle.txt
│ └── support_url.txt
└── screenshots
├── README.txt
└── zh-Hans
├── ....png
└── ....png
FastFile
就是存放我们自定义的指令的地方, 我们cat下FastFile, 发现fastlane已经基于我们之前的选择, 自动生成了打包上传到appstore的lane
:
default_platform(:ios)
platform :ios do
desc "Push a new release build to the App Store"
lane :release do
build_app(workspace: "VoiceOfGod.xcworkspace", scheme: "VoiceOfGod")
upload_to_app_store
end
end
证书管理神器Match
我个人在打包的时候为了避免开发机卡顿 造成效率下降, 所以打包都是在一台mac mini上进行的, 用之前的路数, 需要将开发机的证书导出p12和描述文件 在mini上按照, 即可保证正常.
但是难受的是 每次证书更改/描述文件更新时(例如添加adhoc设备) 就需要两边一起更新, 虽然Xcode现在支持在其内部直接下载, 但是有没有办法可以更省心省力呢?
答案呼之欲出, 这便是 fastlane中著名的action Match
工作原理
其实match工具的核心很简单,就是自动创建一套证书与Profile文件.然后通过Git托管这些文件.在共享机器上面通过下载并把证书装到机器上面.
初始化
在项目目录下执行
fastlane match init
接着我们选择git作为存储容器.
然后创建一个空的git项目, 并将地址粘贴:
[14:11:57]: Please create a new, private git repository to store the certificates and profiles there
[14:11:57]: URL of the Git Repo: https://github.com/yourname/your_match_files.git
此时, fastlane目录下会多出一个MatchFile
, 这就代表你初始化成功了.
生成并证书及描述文件
我们编辑fastlane/FastFile
, 添加一个新的lane, 用来生成证书及描述文件, 并安装.
lane :match_all do
sh "bundle exec fastlane match development"
sh "bundle exec fastlane match adhoc"
sh "bundle exec fastlane match appstore"
end
保存后 执行 fastlane match_all
这样会帮你生成所有环境的证书和描述文件, 同时存到你刚才配置的git地址中, 如果是第一次配置, 会让你配置下 git项目密码, 并且会将此密码存到本机的keychain中.
而之后在其他机器上使用时, 先创建一个新的lane:
lane :match_all_readonly do
sh "fastlane match development --readonly"
sh "fastlane match adhoc --readonly"
sh "fastlane match appstore --readonly"
end
然后在调用 fastlane match_all_readonly,在需要时 手动输入刚才配置的git仓库加密的密码即可, 之后每次打包便不需要手动操作了.
不过也正因为match的问题, 使用ssh进行操作时, 都会卡在git加密密钥验证这个地方. 所以每次打包, 要不就是使用teamviewer来操作, 要不就是使用mini上的jenkins调用mini本地 fastlane 命令的方式来打包.
AdHoc打包
注意在使用gym
前 请确认你的scheme
已经勾选了Share
lane :adhoc do
# sh "pod install --no-repo-update"
puts "开始打包 adhoc"
gym(
clean:true,
scheme:"YourProjectTarget",
configuration:"AdHoc",
export_method:"ad-hoc",
output_directory:"./build",# 打包后的 ipa 文件存放的目录
silent:true,
)
# 使用fir上传
sh "fir p ../build/your.ipa -T YourFirToken"
puts "打包完成"
end
邮件通知
fastlane有一个邮件通知的action, 但是需要信用卡绑定才可以发送邮件, 于是我又找了一个替代品 -- fastlane-plugin-send_e_mail
先添加plugin
fastlane add_plugin send_e_mail
然后在FastFile
中添加一个新的lane:
lane :send_mail do
version = get_version_number(xcodeproj: "your_project.xcodeproj", target: "your_project_target")
#build_number = get_build_number(xcodeproj: "your_project.xcodeproj")
title = "your_app_name (iOS) #{version} 已提交AppStore审核."
send_e_mail(
stmp_server: 'smtp.exmail.qq.com',
user_name: 'xxx@qqqiye.cn',
password: 'xxxxxx',
recipients: ['tom@qqqiye.cn','jeff@qqqiye.cn'],
subject: title,
message_body: "no reply"
)
end
然后直接在其他lane中调用这个send_mail
就可:
desc "Push a new release build to the App Store"
lane :release do
build_app(workspace: "VoiceOfGod.xcworkspace", scheme: "VoiceOfGod")
upload_to_app_store
send_mail
end
关于Deliverfile的一些配置
我的Deliverfile的配置是这样的
# The Deliverfile allows you to store various App Store Connect metadata
# For more information, check out the docs
# https://docs.fastlane.tools/actions/deliver/
force true #强制不显示 preview网页.
#build_number "30" #设置项目的build number
skip_screenshots true #跳过截图上传.
phased_release true #分阶段分发
submit_for_review false #提交完成直接进入review.
问题汇总
increment_build_number报错或者无法使用
Xcode->Build Settings
-> VERSIONING SYSTEM
设置成 Apple Generic
.
error: Provisioning profile "iOS Team Provisioning Profile: " doesn't include signing certificate "iPhone Developer: "
Xcode->Build Settings
-> Code Signing Identity
设置如下即可