Fastlane 入門教學
這篇會透過以下四個步驟,透過 Fastlane 自動化流程
- 透過 match 處理 Certificates 和 Provisioning Profile,分成四種類型 development、adhoc、appstore 和 enterprise
- 透過 gym 來進行編譯打包 ipa 的動作
- 透過 pilot 來推送到 Testflight,同時還可以設定測試資訊
- 透過 deliver 設定 AppStore 相關資訊和自動上傳到 AppStore Connect
首先確認 ruby 版本為最新版本
$ruby --version
跟著流程安裝 fastlane
$sudo gem install fastlane
切換到專案的根目錄,初始化 fastlane
$fastlane init
初始化完成後會在專案目錄下產生一個 fastlane 文件夾
開始操作Fastfile
前,使用 gem 工具 dotenv ,為 fastlane 指定環境變量
gem install dotenv
cd 到 fastlane 文件夾裡,輸入命令touch .env
新建檔案,在檔案中添加如下內容:
XCODE_SCHEME = FastlaneTutorialEXPORT_OUTPUT_DIRECTORY = "./build"
在 Fastfile 中就可以使用以上定義的環境變量
Match
首先在 Gitlab 建立一個新的 private repo,用來存放 Certificate 和 Provisioning Profile,fastlane match init
命令會生成一個 Matchfile
fastlane match init
建立 development 的 Certificate 和 Provisioning Profile,會自動上傳至 apple developer 和 gitlab repo
fastlane match development
回到剛剛建立的 gitlab repo 裡會看到生成這些檔案,certs 裡存放 Certificate 及 .p12 檔,profiles 則是存放著 Provisioning Profile
用來快速同步 Certificates 和 Provisioning Profile 的 lane
Gym
透過命令 fastlane gym init
生成 Gymfile
,在檔案中添加如下內容
scheme("FastlaneTutorial")sdk "iphoneos"clean trueoutput_directory "./build"
用來打包 ipa 到本地資料夾的 lane
上面的 lane
有用到increment_build_number
的 action
,必須在 Build Settings
裡設定 Current Project Version:1
和 Versioning System:Apple Generic
,不然會報錯
Pilot
用來管理 TestFlight,功能如下,了解詳情
打包 ipa 上傳到 TestFlight 和設定 AppStore Connect 上 TestFlight 的測試資訊的 lane
Deliver
透過命令 fastlane deliver init
會生成 Deliverfile
和 metadata
文件夾,然後刪除 metadata
文件夾裡的 .txt 檔,因為 Deliverfile
的優先度比metadata
要高,這邊選用讀取 Deliverfile
裡的設定
fastlane deliver init
cd 到 metadata
文件夾,建立一個設定年齡分級的 json 檔,這部分設定會在 Deliverfile
裡用到
Deliverfile 設定
用來打包 ipa 上傳到 AppStore Connect 的 lane
這篇完整的 fastlane 設置,可以前往這個 repo 查看