1、安装fastlane
1)安装命令:
sudo gem install -n /usr/local/bin fastlane
2)查看版本:
fastlane --version
如果安装成功,会有如下结果输出。
fastlane installation at path:
/Library/Ruby/Gems/2.6.0/gems/fastlane-2.212.1/bin/fastlane
-----------------------------
[✔] 🚀
fastlane 2.212.1
2、初始化fastlane
1)定位到项目根目录,执行初始化
cd dir
fastlane init
2)初始化期间,会有一些选择,根据您的需求键入即可。
[16:35:11]: 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
?
Ambiguous choice. Please choose one of [1, 2, 3, 4, 📸 Automate
screenshots, 👩✈️ Automate beta distribution to TestFlight, 🚀 Automate
App Store distribution, 🛠 Manual setup - manually setup your project to
automate your tasks].
? 1
[17:11:53]: Which is your UI Testing scheme? If you can't find it in this list, make sure it's marked as `Shared` in the Xcode scheme list
1. GlobalChallenge
? 1
[17:11:54]: ------------------------------------
[17:11:54]: --- Automatically upload to iTC? ---
[17:11:54]: ------------------------------------
[17:11:54]: Would you like fastlane to automatically upload all generated screenshots to App Store Connect
[17:11:54]: after generating them?
[17:11:54]: If you enable this feature you'll need to provide your App Store Connect credentials so fastlane can upload the screenshots to App Store Connect
[17:11:54]: Enable automatic upload of localized screenshots to App Store
Connect? (y/n)
n
[17:11:59]: --------------------------------------------------------
[17:11:59]: --- ✅ Successfully generated fastlane configuration ---
[17:11:59]: --------------------------------------------------------
[17:11:59]: Generated Fastfile at path `./fastlane/Fastfile`
[17:11:59]: Generated Appfile at path `./fastlane/Appfile`
[17:11:59]: Gemfile and Gemfile.lock at path `Gemfile`
[17:11:59]: Please check the newly generated configuration files into git along with your project
[17:11:59]: This way everyone in your team can benefit from your fastlane setup
[17:11:59]: Continue by pressing Enter ⏎
根目录会产生一个fastlane文件夹,初始化成功后,文件夹里多了Appfile和Fastfile等文件。
3、对fastlane里文件进行修改
1)编辑Appfile文件。
app_identifier("com.xxxx.xxxx") # The bundle identifier of your app
# apple_id("xxxx@xxxx.com") # Your Apple Developer Portal username
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
2)编辑Fastfile文件。
default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
#fir为任务名称
lane :fir do
# add actions here: https://docs.fastlane.tools/actions
build_app( # 构建app,archive操作
clean: "true",
# 指定工程文件
workspace: "xxxx.xcworkspace",
#打包模式,Release或者Debug
configuration: "Release",
#指定打包所使用的输出方式,目前支持app-store, package, ad-hoc, enterprise, development
export_method: "ad-hoc",
export_options: {
provisioningProfiles: {
#指定打包所使用的证书:"项目bundleid" => "Provisioning Profile文件名"
"com.xxxx.xxxx" => "GC_Ad_Hoc03"
}
},
#ipa包路径
output_directory: "~/Desktop/autoPackaging"
)
end
end
4、打包
1)执行打包命令。
cd dir
fastlane fir
打包成功如下所示。
[09:53:59]: Successfully exported and compressed dSYM file
[09:53:59]: Successfully exported and signed the ipa file:
[09:53:59]: /Users/iss730001004790/Desktop/autoPackaging/xxxx.ipa
+------+------------------+-------------+
| fastlane summary |
+------+------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------+-------------+
| 1 | default_platform | 0 |
| 2 | build_app | 104 |
+------+------------------+-------------+
[09:53:59]: fastlane.tools finished successfully 🎉
2)在桌面找到autoPackaging文件夹,打开可以看到生成的xxxx.app.dSYM.zip和xxxx.ipa文件。