網站首頁 編程語言 正文
概述
APP自動化打包常見的主流工具有Jenkins
、fastlane
。Jenkins
功能強大,但是需要的配置也比較多,團隊較大的可以優先考慮,fastlane是用Ruby語言編寫的一套自動化工具集,比較輕便,配置簡單,使用起來也很方便。本文會詳細的介紹fastlane從安裝到上傳APP到蒲公英的整個流程。
fastlane的安裝
第一步
因為fastlane是用Ruby語言編寫的工具,所以必須保證已經配置好了Ruby開發環境。可以使用如下命令行查看是否安裝了Ruby:
ruby -v
如果有以下提示說明,你已經安裝了Ruby:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin21]
如果沒有安裝需要先安裝ruby,本文對安裝ruby不作教程說明。
第二步
安裝Xcode命令行工具
xcode-select --install
如果沒有安裝,命令會有提示框,根據提示一步一步安裝即可。 如果出現以下命令提示,說明已經安裝成功:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
第三步:
Ruby和Xcode環境都配置好之后,執行以下命令來安裝fastlane:
sudo gem install -n /usr/local/bin fastlane
安裝完成之后,輸入以下命令查看是否安裝成功:
fastlane --version
出現以下提示說明你已經安裝成功了:
fastlane installation at path: /Users/xxxxxx/.rvm/gems/ruby-2.7.0/gems/fastlane-2.206.1/bin/fastlane ----------------------------- [?] ?? fastlane 2.206.1
fastlane的配置
到你的iOS項目下,執行初始化命令:
fastlane init
命令執行完成之后會給出我們如下幾個提示:
[?] ?? [?] Looking for iOS and Android projects in current directory... [16:54:04]: Created new folder './fastlane'. [16:54:04]: Detected an iOS/macOS project in the current directory: 'xxxx.xcworkspace' [16:54:04]: ----------------------------- [16:54:04]: --- Welcome to fastlane ?? --- [16:54:04]: ----------------------------- [16:54:04]: fastlane can help you with all kinds of automation for your mobile app [16:54:04]: We recommend automating one task first, and then gradually automating more over time [16:54:04]: 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 ?
命令執行到最后有What would you like to use fastlane for?
提示,此時fastlane列出幾個選項,需要我們告訴它使用fastlane需要執行哪種操作:
- 第一種獲取App Store的App預覽照片。
- 第二種打包上傳至TestFlight工具上。
- 第三種打包上傳到App Store。
- 第四種自定義打包方式。
以上四種方式根據自己的需要自行選擇,本文主要介紹打包上傳至第三方平臺,所以選擇4
自定義打包方式。選擇完成之后,fastlane會在我們項目中創建fastlane文件
[16:54:32]: ------------------------------------------------------------ [16:54:32]: --- Setting up fastlane so you can manually configure it --- [16:54:32]: ------------------------------------------------------------ [16:54:32]: Installing dependencies for you... [16:54:32]: $ bundle update [16:54:40]: -------------------------------------------------------- [16:54:40]: --- ? Successfully generated fastlane configuration --- [16:54:40]: -------------------------------------------------------- [16:54:40]: Generated Fastfile at path `./fastlane/Fastfile` [16:54:40]: Generated Appfile at path `./fastlane/Appfile` [16:54:40]: Gemfile and Gemfile.lock at path `Gemfile` [16:54:40]: Please check the newly generated configuration files into git along with your project [16:54:40]: This way everyone in your team can benefit from your fastlane setup [16:54:40]: Continue by pressing Enter ?
創建好fastlane文件夾之后,Appfile
是編輯我們相關App和開發者賬號信息的,一般不需要我們去手動修改。Fastfile
是我們對自動打包這個過程的完整配置,默認的Fastfile文件內容如下:
# 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 :custom_lane do # add actions here: https://docs.fastlane.tools/actions end end
打包并自動上傳 App 到蒲公英
安裝蒲公英的 fastlane 插件
fastlane add_plugin pgyer
編輯Fastlane 的配置文件 fastlane/Fastfile
lane :develop do target = "demo" configuration = "Debug" gym(scheme: target, configuration: configuration, export_method:"development") pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e") end
以下是蒲公英平臺的說明:
- 以上的
api_key
和user_key
,請開發者在自己賬號下的應用管理
-App概述
-API
中可以找到,并替換到以上相應的位置。 - 在 Xcode 8.3 和 Xcode 8.3 以后的版本中,對于
build_app
的export_method
的值,需要根據開發者的打包類型進行設置,可選的值有:app-store
、ad-hoc
、development
、enterprise
。對于 Xcode 8.3 以下的版本,則不需要設置export_method
。
經過以上配置后,就可以使用 Fastlane 來打包 App,并自動上傳到蒲公英了。在終端下,定位到項目所在目錄,輸入以下命令即可:
fastlane develop
在成功的情況下,可以看到類似下面的信息:
[18:37:22]: Successfully exported and compressed dSYM file
[18:37:22]: Successfully exported and signed the ipa file:
[18:37:22]: /Users/xxx/Documents/workCode/xxxxx.ipa
[18:37:22]: -------------------
[18:37:22]: --- Step: pgyer ---
[18:37:22]: -------------------
[18:37:22]: The pgyer plugin is working.
[18:37:22]: build_file: /Users/dddd/Documents/workCode/xxxx.ipa
[18:37:22]: Start upload /Users/dddd/Documents/workCode/xxx.ipa to pgyer...
[18:37:43]: Upload success. Visit this URL to see: https://www.pgyer.com/xxxxx
+------+------------------+-------------+
| ? ? ? ? ? fastlane summary ? ? ? ? ? ?|
+------+------------------+-------------+
| Step | Action ? ? ? ? ? | Time (in s) |
+------+------------------+-------------+
| 1 ? ?| default_platform | 0 ? ? ? ? ? |
| 2 ? ?| gym ? ? ? ? ? ? ?| 61 ? ? ? ? ?|
| 3 ? ?| pgyer ? ? ? ? ? ?| 20 ? ? ? ? ?|
+------+------------------+-------------+
[18:37:43]: fastlane.tools finished successfully ??
- 設置一個版本更新時的描述信息:
lane :develop do build_app(export_method: "development") pgyer(api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e", update_description: "update by fastlane") end
打包上傳到Testflight
在Fastfile文件中加入下面命令:
desc "打包上傳到Testflight" lane :beta do # add actions here: https://docs.fastlane.tools/actions target = "demo" configuration = "Release" gym(scheme: target, configuration: configuration, export_method:"app-store") upload_to_testflight( username: "xxxx@dd.com", app_identifier: "com.xxxx", )
在命令行輸入:
fastlane beta
打包上傳的過程中會讓你輸入蘋果賬號的密碼,并且有可能會報下面的錯:
[00:20:28]: Login successful
[00:20:31]: Ready to upload new build to TestFlight (App: fffff)...
[00:20:40]: Transporter transfer failed.
[00:20:40]:?
[00:20:40]: Please sign in with an app-specific password. You can create one at appleid.apple.com. (-22910)
[00:20:41]:?
[00:20:41]: Your account has 2 step verification enabled
[00:20:41]: Please go to https://appleid.apple.com/account/manage
[00:20:41]: and generate an application specific password for
[00:20:41]: the iTunes Transporter, which is used to upload builds
[00:20:41]:?
[00:20:41]: To set the application specific password on a CI machine using
[00:20:41]: an environment variable, you can set the
[00:20:41]: FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD variable
這是因為你的APPLE賬號開啟了雙重驗證,注意這句提示Please sign in with an app-specific password
用app專用密碼登錄,提示你創建一個app專用密碼登錄Transporter,關于怎么創建app專用密碼本人不做講解,可以自行百度或者谷歌,使用app專用賬號即可解決此問題。
原文鏈接:https://juejin.cn/post/7112417164304318477
相關推薦
- 2022-08-05 C語言示例講解while循環語句的用法_C 語言
- 2022-07-12 windows系統-串口設備導致鼠標亂跳的問題
- 2022-04-03 深入了解Python如何操作MongoDB_python
- 2022-11-01 React?Hooks?useReducer?逃避deps組件渲染次數增加陷阱_React
- 2022-10-16 安裝出現:Requirement?already?satisfied解決辦法_python
- 2022-10-10 AOSP源碼下載示例代碼_Android
- 2022-09-30 Python中4種實現數值的交換方式_python
- 2022-04-25 C#使用游標實現補間函數_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支