您好,登錄后才能下訂單哦!
這篇文章主要介紹“fastlane自動化打包iOS APP示例代碼分析”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“fastlane自動化打包iOS APP示例代碼分析”文章能幫助大家解決問題。
APP自動化打包常見的主流工具有Jenkins
、fastlane
。Jenkins
功能強大,但是需要的配置也比較多,團隊較大的可以優先考慮,fastlane是用Ruby語言編寫的一套自動化工具集,比較輕便,配置簡單,使用起來也很方便。
第一步
因為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 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
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
在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專用賬號即可解決此問題。
關于“fastlane自動化打包iOS APP示例代碼分析”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。