fastlane的使用
-
fastlane简介
Fastlane基于ruby环境自动化工具集,它不是一个工具,它是一系列的工具的集合,基本上涵盖了打包,签名,测试,部署,发布,库管理等等移动开发中涉及到的内容。 同时该套件也支持与 Jenkins 、CocoaPods、xctools 等其他第三方工具的集成。
-
安装 Xcode command line tools:
xcode-select --install
安装过会提示已经安装;
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
-
安装Fastlane
sudo gem install fastlane
-
fastlane 初始化和使用
cd 到ios目录下打开工程所在目录,执行fastlane init
出现如下提示:
[图片上传失败...(image-cec82c-1747381885092)]
选择****4 ,手动设置工程文件;然后一路****enter
[图片上传失败...(image-a6349c-1747381885092)]
然后可看到工程目录下多了几个文件:
[图片上传失败...(image-60636-1747381885092)]
其中Appfile、Fastfile就是我们需要修改的文件;
- Appfile:App相关的信息,写以下几项就可以:
app_identifier("xxxxxxxxx") # The bundle identifier of your app
apple_id("xxxxxxx") # Your Apple email address
team_id("xxxxxxxx") # Developer Portal Team ID
itc_team_id("xxxxx") # App Store Connect Team ID
[图片上传失败...(image-86e774-1747381885092)]
[图片上传失败...(image-c7a485-1747381885092)]
- Fastfile:描述打包相关的配置信息,初始内容如下:
[图片上传失败...(image-d79b69-1747381885092)]
一个lane 可理解为就是一个任务,
我们打包发布到蒲公英是一个任务,打包发布到App Store也是一个任务;
lane中可添加多个action,也就是具体的操作,
比如打包方法操作是一个action,
发布蒲公英操作也是一个action;
fastlane打包以及发布到蒲公英
-
在Fastfile文件中填写(*)
lane :release do
gym(
clean: true, # 是否清空工程
silent: true, # 运行时不显示详细日志
#project: "danceRN.xcodeproj",
export_method: 'ad-hoc', # 导出ad-hoc包
output_directory: './fastlane/build', # 生成的 .ipa 文件存放位置
output_name:"danceRN.ipa", # 最终生成的 .ipa 文件名称
scheme: 'danceRN', # Xcode 里的 Scheme
configuration: 'Release', # Release 版本适用于发布
include_symbols:true, # 包含符号表,用于崩溃分析(生成 .dSYM 文件)
export_xcargs: "-allowProvisioningUpdates", # 允许更新 Provisioning Profile(避免证书/描述文件更新失败)
)
pgyer(
api_key: "e09a773739c4e94e199bf84612cd311e", # 蒲公英的apikey
update_description: "服务:生产环境;打包:生产包" # 蒲公英的描述
)
end
用到的不多,其他参数还很多具体参看: gym方法及参数配置-http://docs.fastlane.tools/actions/gym/#gym
-
添加蒲公英插件
cd 打开工程所在目录,执行如下:
fastlane add_plugin pgyer
具体参考:https://www.pgyer.com/doc/view/fastlane
-
终端执行
fastlane release (可理解为就是我们的任务名)
然后剩下的就不用我们管了,它会自动的帮我们处理余下的所有工作;
fastlane打包以及发布到appstore
-
在Fastfile文件中填写
desc "以 app-store 方式打包并上传到 iTunes Connect"
lane :appconnect do
puts "自动生成 Provisioning Profiles 文件"
puts "以 app-store 方式打包"
gym(
# 指定打包所使用的输出方式 (可选: app-store, package, ad-hoc, enterprise, development)
export_method: "app-store",
# 指定项目的 scheme 名称
scheme: "danceRN",
# 指定输出的文件夹地址
output_directory: './fastlane/build',
output_name:"danceRN.ipa",
# 指定打包方式 (可选: Release, Debug)
configuration: "Release",
export_xcargs: "-allowProvisioningUpdates"
)
#puts "上传 ipa 包到 TestFlight"
#pilot(team_name: "Shenzhen Kuai Feike Logistics Co., Ltd.")
puts "上传 ipa 包到 iTunes Connect"
# 设置apple专用密码
ENV['FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD'] = "tdqe-pvuj-zowz-ikup"
deliver(
release_notes: { # 更新日志
'en-US' => "Bug fixes and performance improvements.", # 英文
'ar-SA' => "إصلاحات الأخطاء وتحسينات الأداء.", # 阿拉伯文(沙特阿拉伯)
'hi' => "बग फिक्स और प्रदर्शन सुधार।", # 北印度文(印度)
'de-DE' => "Fehlerbehebungen und Leistungsverbesserungen.", # 德文(德国)
'ru' => "Исправления ошибок и улучшение производительности.", # 俄文(俄罗斯)
'fr-FR' => "Corrections de bugs et améliorations des performances.", # 法文(法国)
'nl-NL' => "Foutoplossingen en prestatieverbeteringen.", # 荷兰文(荷兰)
'no' => "Feilrettinger og ytelsesforbedringer.", # 挪威文(挪威)
'pt-BR' => "Correções de bugs e melhorias de desempenho.", # 葡萄牙文(巴西)
'ja' => "バグ修正とパフォーマンスの改善。", # 日文(日本)
'sv' => "Felrättningar och prestandaförbättringar.", # 瑞典文(瑞典)
'es-MX' => "Correcciones de errores y mejoras en el rendimiento.", # 西班牙文(墨西哥)
'he' => "תיקוני באגים ושיפורי ביצועים." # 希伯来文(以色列)
},
# 跳过截图上传
skip_screenshots: true,
# 跳过元数据上传
# skip_metadata: true,
# 不跳过元数据上传, 即 会上传 App Store Connect 相关的应用元数据(比如应用名称、描述、关键词、更新日志等)。
skip_metadata: false,
#跳过上传ipa或pkg到iTunes Connect
skip_binary_upload: false,
# 跳过审核直接上传
force: true,
# 在上传所有内容后提交新版本进行审核
submit_for_review: true,
# 一旦应用程序审核通过,该应用会自动发布App Store
automatic_release: false
)
end
第一种授权(常用):
注意FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD专用密码的替换 apple专用密码可在官网https://account.apple.com/account/manage,安全里找到
ps: 检测专用秘钥是否可用
xcrun altool --validate-app -f ./fastlane/build/musent.ipa -t ios -u mumu19920210@sina.com -p 'kjiw-bsni-xatl-shga'
./fastlane/build/musent.ipa -> 文件目录(换成自己的)
mumu19920210@sina.com -> 自己的账号(换成自己的)
kjiw-bsni-xatl-shga -> 专用秘钥(换成自己的)
[图片上传失败...(image-c5d557-1747381885092)]
第二种授权(如下仅供参考):
或者——其次还可以使用 fastlane spaceauth
[图片上传失败...(image-99bd0e-1747381885092)]
ENV["FASTLANE_SESSION"] = '---\n- !ruby/object:HTTP::Cookie\n name: myacinfo\n value: DAWTKNV323952cf8084a204fb20ab2508441a07d02d3e8703d5c09e50b6b689bd9820f2faa018918ebd00c5018e8fc4e0c60fed3c72bb5809520b26c2fd6a31ea7ecbea0f66068d9606af018d7842cc3bdfcff7517bc3377dbfdc69a7b5c061095cdd20fdb12aa1761a7cea45fcec8e8f24139f2804dd52e46ff3085ab74d1d239c9192631cf51492b2cb61e4b8e4d1dc803a515254b6ae38858cda273a24068a2912e0844cef2b6d04cd43860ca8219eb93f21abce45c8c9e15d6cd73df64fc6446b36f21ed58757c4eef40ac3bfaac0a4ba66cf6303f1e22deae550cf5f373792e5a9851d88a3163e5acf74868432edcf198bad5229b8dd2e66211f5c55f2af0d947cc056825167c574a796372c56e40177844b75fe8836e9af6607787e8a397f5cca87819c7b06c3941d8f03155152dc495f90e617be328a4b2e842fb62b638de8fa0368e06266b9c6fd59a4cb1ae4aa5e33a19dea1c230a659db531e0f02471e8c142d55afff1912f9dc7e955c557d2bae5c3470ea1f16ea3a996c1f532423cfe87af7e459a0fba191dd72c720aa1bff7826b1542b2295d415823b9df04e0f8764e3da1814649f2a0c90f0ce0e8f7e4c3f750debb308935d55d1681690f54f4b7337a26df294308e464f55fcac5ee3628a11e49fe7133069621cd86471039068f8a195c264b42bbf27ba659c8459c0fb458ef748c447ea30a572638658bed0266f962f9cbf1feeb0ffae6d7c74370152679a39c986fc319d181a473fdf3b23cc1159b06dc6a93df85e601dd8ca64dd76cc10fab38413b43c87422a762619c327ed77caf552b728e457c03ec372f783471f07945e0a53ee28f20f434d5b7dc50472e822a239b973c27b7a02ef740c2888382a229e146581f46cb46cc5f72894aa1bbdca95585a47V3\n domain: apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires:\n max_age:\n created_at: 2025-05-16 09:38:27.505091000 +08:00\n accessed_at: 2025-05-16 09:38:27.512505000 +08:00\n- !ruby/object:HTTP::Cookie\n name: DES5c63ba1131e7002469e4c74ab38f4ab7b\n value: HSARMTKNSRVXWFlafkrI2ldl2ZvggPcfzc0cVKB01lg64bfBq3wt1DZpLjhsU3RjyoQKX3O8KiMl91T0M85v6b6JOh+v4eyZZESytEJ7RT7To89mQSadHJrb4mdpUnPJpH7N/U8/dzdwnwqC486yf/7K4l4buBwle+iHQlL9j+5cyGdwbj62gzAV7XkH7Q==SRVX\n domain: idmsa.apple.com\n for_domain: true\n path: "/"\n secure: true\n httponly: true\n expires:\n max_age: 2592000\n created_at: &1 2025-05-16 09:38:27.504906000 +08:00\n accessed_at: *1\n- !ruby/object:HTTP::Cookie\n name: dqsid\n value: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDczNTk1MDcsImp0aSI6IjNMWFBNQXQ2UGpkNUFSclRkWXdaS0EifQ.xNVkRuyAEk80WopdVK7Sc1FJGHAJETGGPdQXEJTMWFM\n domain: appstoreconnect.apple.com\n for_domain: false\n path: "/"\n secure: true\n httponly: true\n expires:\n max_age: 1800\n created_at: &2 2025-05-16 09:38:28.309489000 +08:00\n accessed_at: *2\n'
参考:
fastlane的具体命令含义等(在里面搜):
-
在package.json中添加如下
"dev": "cd ios && fastlane dev && cd ..",
"release": "cd ios && fastlane release && cd ..",
"appstore": "cd ios && fastlane appconnect && cd ..",
终端执行
yarn dev 打测试包并上传到蒲公英
yarn release 打生产包并上传到蒲公英
yarn appstore 打生产包提审到appstore
举例:
执行yarn appstore,先是打app-store包
[图片上传失败...(image-8eb009-1747381885092)]
上传iap:
[图片上传失败...(image-19b4cc-1747381885092)]
提交审核:
[图片上传失败...(image-659f97-1747381885092)]
Ps: 由于Appfile文件里的配置弄错,导致一直没上传成功,因此;
请务必检查如下部分:
[图片上传失败...(image-30bb2b-1747381885092)]
[图片上传失败...(image-8848c3-1747381885092)]
[图片上传失败...(image-47a537-1747381885092)]
# 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 :dev do
app_url = "https://www.pgyer.com/8b3D0JH0"
updateLog = "1. <font color=DeepPink>优化bug</font>"
sh("echo 'updateLog: \n#{updateLog}'")
updateText = " # iOS测试环境 \n #{updateLog} "
gym(
clean: true,
silent: true,
#project: "danceRN.xcodeproj",
export_method: 'ad-hoc',
output_directory: './fastlane/build',
output_name:"musent",
scheme: 'Development',
configuration: 'Development',
include_symbols:true,
export_xcargs: "-allowProvisioningUpdates",
)
pgyer(
api_key: "e09a773739c4e94e199bf84612cd311e",
update_description: "服务:测试环境;打包:测试包"
)
end
desc "Description of what the lane does"
lane :release do
app_url = "https://www.pgyer.com/8b3D0JH0"
updateLog = "1. <font color=DeepPink>优化bug</font>"
sh("echo 'updateLog: \n#{updateLog}'")
updateText = " # iOS测试环境 \n #{updateLog} "
gym(
clean: true,
silent: true,
#project: "danceRN.xcodeproj",
export_method: 'ad-hoc',
output_directory: './fastlane/build',
output_name:"musent",
scheme: 'Staging',
configuration: 'Staging',
include_symbols:true,
export_xcargs: "-allowProvisioningUpdates",
)
pgyer(
api_key: "e09a773739c4e94e199bf84612cd311e",
update_description: "服务:生产环境;打包:生产包"
)
end
desc "Description of what the lane does"
lane :push do
puts "自动生成 Provisioning Profiles 文件"
puts "以 app-store 方式打包"
puts "上传 ipa 包到 iTunes Connect"
ENV['FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD'] = "kjiw-bsni-xatl-shga"
gym(
clean: true,
silent: true,
#project: "danceRN.xcodeproj",
export_method: 'app-store',
output_directory: './fastlane/build',
output_name:"musent",
scheme: 'Musent',
configuration: 'Release',
include_symbols:true,
export_xcargs: "-allowProvisioningUpdates",
)
deliver(
#这是修复配置错误,而写下的代码,可忽略
#username:"mumu19920210@sina.com",
#ipa: '/Users/tuling/Documents/sunoai/sunoai-rn/ios/fastlane/build/musent.ipa',
release_notes: { # 更新日志
'en-US' => "Bug fixes and performance improvements.", # 英文
'ar-SA' => "إصلاحات الأخطاء وتحسينات الأداء.", # 阿拉伯文(沙特阿拉伯)
'hi' => "बग फिक्स और प्रदर्शन सुधार।", # 北印度文(印度)
'de-DE' => "Fehlerbehebungen und Leistungsverbesserungen.", # 德文(德国)
'ru' => "Исправления ошибок и улучшение производительности.", # 俄文(俄罗斯)
'fr-FR' => "Corrections de bugs et améliorations des performances.", # 法文(法国)
'nl-NL' => "Foutoplossingen en prestatieverbeteringen.", # 荷兰文(荷兰)
'no' => "Feilrettinger og ytelsesforbedringer.", # 挪威文(挪威)
'pt-BR' => "Correções de bugs e melhorias de desempenho.", # 葡萄牙文(巴西)
'ja' => "バグ修正とパフォーマンスの改善。", # 日文(日本)
'sv' => "Felrättningar och prestandaförbättringar.", # 瑞典文(瑞典)
'es-MX' => "Correcciones de errores y mejoras en el rendimiento.", # 西班牙文(墨西哥)
'he' => "תיקוני באגים ושיפורי ביצועים." # 希伯来文(以色列)
},
# 跳过截图上传
skip_screenshots: true,
# 跳过元数据上传
# skip_metadata: true,
# 不跳过元数据上传, 即 会上传 App Store Connect 相关的应用元数据(比如应用名称、描述、关键词、更新日志等)。
skip_metadata: false,
#跳过上传ipa或pkg到iTunes Connect
skip_binary_upload: false,
# 跳过审核直接上传
force: true,
# 在上传所有内容后提交新版本进行审核
submit_for_review: true,
# 一旦应用程序审核通过,该应用会自动发布App Store
automatic_release: false
)
end
end