使用 Fastlane 打包上傳到蒲公英
一、Fastlane 簡介
Fastlane 是一款為 iOS 和 Android 開發(fā)者提供的自動化構(gòu)建工具,它可以幫助開發(fā)者將 App 打包、簽名、測試、發(fā)布、信息整理、提交 App Store 等工作完整的連接起來,實(shí)現(xiàn)完全自動化的工作流,如果使用得當(dāng),可以顯著的提高開發(fā)者的開發(fā)效率。
為了將 Fastlane 的自動化工作流與蒲公英結(jié)合起來,需要安裝蒲公英插件,該插件可以將 Fastlane 打包生成的 App 可以自動上傳到蒲公英。
二、使用 Homebrew 安裝 Fastlane
如果沒有安裝,請參考:官方安裝指南
執(zhí)行命令:
brew install fastlane
三、安裝蒲公英的 Fastlane 插件
fastlane add_plugin pgyer
四、在 Fastlane 啟動蒲公英插件
1、初始化Fastlane
在使用 Fastlane 之前,我們首先需要在項(xiàng)目中初始化 Fastlane。首先進(jìn)入 App 的開發(fā)目錄,執(zhí)行以下命令來初始化 Fastlane:
fastlane init
執(zhí)行命令之后如下:
? fastlane init [?] ?? +------------------------------------------+ | Used plugins | +-----------------------+---------+--------+ | Plugin | Version | Action | +-----------------------+---------+--------+ | fastlane-plugin-pgyer | 0.2.9 | pgyer | +-----------------------+---------+--------+ [?] Looking for iOS and Android projects in current directory... [14:54:57]: Created new folder './fastlane'. [14:54:57]: Detected an iOS/macOS project in the current directory: 'Cgzl.xcworkspace' [14:54:57]: ----------------------------- [14:54:57]: --- Welcome to fastlane ?? --- [14:54:57]: ----------------------------- [14:54:57]: fastlane can help you with all kinds of automation for your mobile app [14:54:57]: We recommend automating one task first, and then gradually automating more over time [14:54:57]: 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 ? 4 [14:57:18]: ------------------------------------------------------------ [14:57:18]: --- Setting up fastlane so you can manually configure it --- [14:57:18]: ------------------------------------------------------------ [14:57:18]: Installing dependencies for you... [14:57:18]: $ bundle update [14:57:23]: -------------------------------------------------------- [14:57:23]: --- ? Successfully generated fastlane configuration --- [14:57:23]: -------------------------------------------------------- [14:57:23]: Generated Fastfile at path `./fastlane/Fastfile` [14:57:23]: Generated Appfile at path `./fastlane/Appfile` [14:57:23]: Gemfile and Gemfile.lock at path `Gemfile` [14:57:23]: Please check the newly generated configuration files into git along with your project [14:57:23]: This way everyone in your team can benefit from your fastlane setup [14:57:23]: Continue by pressing Enter ?
你想用快車道做什么?
- ??自動截屏
- ????自動測試分發(fā)TestFlight
- ??自動化應(yīng)用商店分銷
- ??手動設(shè)置-手動設(shè)置您的項(xiàng)目自動化您的任務(wù)
這邊選擇 4, 隨后一致按enter,成功之后項(xiàng)目里多了這三個(gè)文件:

2、編輯Fastfile
執(zhí)行上述命令后,F(xiàn)astlane 會自動在 App 目錄中生成 fastlane 目錄,其中就會有 Fastlane 的配置文件 fastlane/Fastfile,這里,我們用 vim 打開:
vim ./fastlane/Fastfile
然后,我們找到我們在用的工作流(action),在 build_app 指令后,加入蒲公英插件的配置信息。例如:
lane :beta do build_app(export_method: "ad-hoc") pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", update_description: "update by fastlane") end
3、打包并自動上傳 App 到蒲公英
經(jīng)過以上配置后,就可以使用 Fastlane 來打包 App,并自動上傳到蒲公英了。在終端下,定位到項(xiàng)目所在目錄,輸入以下命令即可:
fastlane beta
在成功的情況下,可以看到類似下面的信息:

進(jìn)入蒲公英可看到

注意事項(xiàng):
1、蒲公英api_key獲取

參考:

浙公網(wǎng)安備 33010602011771號