您好,登錄后才能下訂單哦!
這篇文章主要介紹“fastlane自動化打包iOS APP示例代碼分析”的相關(guān)知識,小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“fastlane自動化打包iOS APP示例代碼分析”文章能幫助大家解決問題。
APP自動化打包常見的主流工具有Jenkins
、fastlane
。Jenkins
功能強(qiáng)大,但是需要的配置也比較多,團(tuán)隊(duì)較大的可以優(yōu)先考慮,fastlane是用Ruby語言編寫的一套自動化工具集,比較輕便,配置簡單,使用起來也很方便。
第一步
因?yàn)閒astlane是用Ruby語言編寫的工具,所以必須保證已經(jīng)配置好了Ruby開發(fā)環(huán)境??梢允褂萌缦旅钚胁榭词欠癜惭b了Ruby:
ruby -v
如果有以下提示說明,你已經(jīng)安裝了Ruby:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin21]
如果沒有安裝需要先安裝ruby,本文對安裝ruby不作教程說明。
第二步
安裝Xcode命令行工具
xcode-select --install
如果沒有安裝,命令會有提示框,根據(jù)提示一步一步安裝即可。 如果出現(xiàn)以下命令提示,說明已經(jīng)安裝成功:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
第三步:
Ruby和Xcode環(huán)境都配置好之后,執(zhí)行以下命令來安裝fastlane:
sudo gem install -n /usr/local/bin fastlane
安裝完成之后,輸入以下命令查看是否安裝成功:
fastlane --version
出現(xiàn)以下提示說明你已經(jīng)安裝成功了:
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
命令執(zhí)行完成之后會給出我們?nèi)缦聨讉€提示:
[?] ???? [?] 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 ?
命令執(zhí)行到最后有What would you like to use fastlane for?
提示,此時(shí)fastlane列出幾個選項(xiàng),需要我們告訴它使用fastlane需要執(zhí)行哪種操作:
第一種獲取App Store的App預(yù)覽照片。
第二種打包上傳至TestFlight工具上。
第三種打包上傳到App Store。
第四種自定義打包方式。
以上四種方式根據(jù)自己的需要自行選擇,本文主要介紹打包上傳至第三方平臺,所以選擇4
自定義打包方式。選擇完成之后,fastlane會在我們項(xiàng)目中創(chuàng)建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 ?
創(chuàng)建好fastlane文件夾之后,Appfile
是編輯我們相關(guān)App和開發(fā)者賬號信息的,一般不需要我們?nèi)ナ謩有薷摹?code>Fastfile是我們對自動打包這個過程的完整配置,默認(rèn)的Fastfile文件內(nèi)容如下:
# 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
,請開發(fā)者在自己賬號下的 應(yīng)用管理
- App概述
- API
中可以找到,并替換到以上相應(yīng)的位置。
在 Xcode 8.3 和 Xcode 8.3 以后的版本中,對于 build_app
的 export_method
的值,需要根據(jù)開發(fā)者的打包類型進(jìn)行設(shè)置,可選的值有:app-store
、ad-hoc
、development
、enterprise
。對于 Xcode 8.3 以下的版本,則不需要設(shè)置 export_method
。
經(jīng)過以上配置后,就可以使用 Fastlane 來打包 App,并自動上傳到蒲公英了。在終端下,定位到項(xiàng)目所在目錄,輸入以下命令即可:
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 ????
設(shè)置一個版本更新時(shí)的描述信息:
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
打包上傳的過程中會讓你輸入蘋果賬號的密碼,并且有可能會報(bào)下面的錯:
[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
這是因?yàn)槟愕腁PPLE賬號開啟了雙重驗(yàn)證,注意這句提示Please sign in with an app-specific password
用app專用密碼登錄,提示你創(chuàng)建一個app專用密碼登錄Transporter,關(guān)于怎么創(chuàng)建app專用密碼本人不做講解,可以自行百度或者谷歌,使用app專用賬號即可解決此問題。
關(guān)于“fastlane自動化打包iOS APP示例代碼分析”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點(diǎn)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。