環(huán)境配置
安裝 fastlane (以下操作二選一)
1.1 使用 homebrew 管理(未安裝 homebrew 可以點(diǎn)擊查看如何安裝)
brew install fastlane
1.2 使用 gem 安裝
gem install fastlane
若提示權(quán)限不足
sudo gem install fastlane
物料配置
Apple ID + 密碼 + 此賬號(hào)雙重認(rèn)證驗(yàn)證碼
1 在桌面創(chuàng)建一個(gè)文件夾
我創(chuàng)建了一個(gè)名為 fastlaneTest 的文件夾在桌面

fastlaneTest
2 在終端 CD 到該文件夾目錄下
cd /Users/aken/Desktop/fastlaneTest
3 初始化 fastlane
fastlane init

image.png
輸入 y

image.png
看見 Continue by pressing Enter 就敲擊回車,不出意外敲擊三次回車就行了。

image.png
Python 示例腳本
有了以上準(zhǔn)備,將腳本中備注需要替換的物料替換成你自己的物料,就可以運(yùn)行腳本了,首次使用腳本會(huì)在終端提示輸入 蘋果開發(fā)者登入密碼 以及雙重驗(yàn)證碼,驗(yàn)證過后,會(huì)在本地存貯一個(gè)月的有效期。
import subprocess
import os
# 賬號(hào),要填的bunld id,app名字
def generate_fastfile(appleid, app_identifier, app_name):
fastfile_content = f'''
default_platform(:iOS)
platform :iOS do
lane :create_tb do
produce(
username: "{appleid}",
app_identifier: "{app_identifier}",
app_name: "{app_name}",
language: "en-US",
)
end
end
'''
# 替換為你自己桌面文件的絕對(duì)路勁
with open('/Users/aken/Desktop/fastlaneTest/fastlane/Fastfile', 'w') as file:
file.write(fastfile_content)
# 執(zhí)行 fastlane
def call_fastlane():
try:
# 替換為你自己桌面文件的絕對(duì)路勁
os.chdir("/Users/aken/Desktop/fastlaneTest") # 切換到指定路徑
subprocess.run(['fastlane', 'create_tb'], check=True)
except subprocess.CalledProcessError as e:
print(f"Error occurred: {e}")
if __name__ == "__main__":
# 替換成你的蘋果開發(fā)者賬號(hào)
appleid = "xxx"
# 填入你想創(chuàng)建的 bundle id
app_identifier = "xxx.xxx.xxxx"
# 你的 app名字
app_name = "xxxxx"
# 執(zhí)行文檔腳本
generate_fastfile(appleid,app_identifier, app_name)
# 執(zhí)行創(chuàng)建腳本
call_fastlane()