iOS中如何使用Fastlane實(shí)現(xiàn)自動(dòng)化打包和發(fā)布-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)iOS中如何使用Fastlane實(shí)現(xiàn)自動(dòng)化打包和發(fā)布,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)專注于中大型企業(yè)的網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計(jì)客戶成百上千,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對(duì)接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注成都品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開發(fā),在前進(jìn)的路上,與客戶一起成長(zhǎng)!

安裝

1、首先要安裝正確的 Ruby 版本。在終端窗口中用下列命令來確認(rèn):

ruby -v

2、然后檢查 Xcode 命令行工具是否安裝。在終端窗口中輸入命令:

xcode-select --install

如果未安裝,終端會(huì)開始安裝,如果報(bào)錯(cuò)誤:command line tools are already installed, use "Software Update" to install updates.代表已經(jīng)安裝。

3、以上依賴配置好之后就可以通過 rubygem 進(jìn)行安裝了:

$ sudo gem install fastlane

安心等待一會(huì),fastlane就安裝完成了。

初始化

打開終端,cd到你的工程目錄,然后執(zhí)行fastlane init:

$ cd to/your/ios/project 
$ fastlane init
[14:21:43]: Detected iOS/Mac project in current directory...
[14:21:43]: This setup will help you get up and running in no time.
[14:21:43]: fastlane will check what tools you're already using and set up
[14:21:43]: the tool automatically for you. Have fun! 
[14:21:43]: Created new folder './fastlane'.
[14:21:43]: $ xcodebuild -showBuildSettings -project ./xxx.xcodeproj
[14:21:48]: Your Apple ID (e.g. fastlane@krausefx.com): xxx@xxx.xom
[14:21:54]: Verifying that app is available on the Apple Developer Portal and iTunes Connect...
[14:21:54]: Starting login with user 'xxx@xxx.com'
+----------------+--------------------------------------+
|          Detected Values          |
+----------------+--------------------------------------+
| Apple ID    | xxx@xxx.com          |
| App Name    | xxx              |
| App Identifier | com.xxx.xxx        |
| Project    | /Users/lisong/Desktop/xxx/x |
|        | xx.xcodeproj           |
+----------------+--------------------------------------+
[14:22:06]: Please confirm the above values (y/n)
y
[14:22:09]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
[14:22:09]: Loading up 'deliver', this might take a few seconds
[14:22:09]: Login to iTunes Connect (xxx@xxx.com)
[14:22:13]: Login successful
+-----------------------+------------------------+
|       deliver 2.30.1 Summary       |
+-----------------------+------------------------+
| screenshots_path   | ./fastlane/screenshots |
| metadata_path     | ./fastlane/metadata  |
| username       | xxx@xxx.com   |
| app_identifier    | com.xxx.xxx |
| edit_live       | false         |
| platform       | ios          |
| skip_binary_upload  | false         |
| skip_screenshots   | false         |
| skip_metadata     | false         |
| force         | false         |
| submit_for_review   | false         |
| automatic_release   | false         |
| dev_portal_team_id  | WKR87TTKML       |
| overwrite_screenshots | false         |
+-----------------------+------------------------+
[14:22:21]: Writing to 'fastlane/metadata/zh-Hans/description.txt'
...
[14:22:21]: Writing to 'fastlane/metadata/review_information/notes.txt'
[14:22:21]: Successfully created new configuration files.
[14:22:22]: Successfully downloaded large app icon
[14:22:22]: Downloading all existing screenshots...
[14:22:27]: Downloading existing screenshot '1_iphone4_1.1.jpg' for language 'zh-Hans'
···
[14:22:34]: Downloading existing screenshot '5_iphone6_5.5.jpg' for language 'zh-Hans'
[14:22:34]: Successfully downloaded all existing screenshots
[14:22:34]: Successfully created new Deliverfile at path 'fastlane/Deliverfile'
[14:22:34]: $ xcodebuild -list -project ./xxx.xcodeproj
[14:22:35]: 'snapshot' not enabled.
[14:22:35]: 'cocoapods' enabled.
[14:22:35]: 'carthage' not enabled.
[14:22:35]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[14:22:35]: fastlane will collect the number of errors for each action to detect integration issues
[14:22:35]: No sensitive/private information will be uploaded
[14:22:35]: Learn more at https://github.com/fastlane/fastlane#metrics
[14:22:35]: Successfully finished setting up fastlane

在 “Your Apple ID” 這一步輸入蘋果開發(fā)者賬號(hào)。在“Please confirm the above values”這一步,確認(rèn)信息,沒問題輸入 y。然后,fastlane 會(huì)進(jìn)行一系列的初始化操作,包括下載 App Store 上的元數(shù)據(jù)和截屏文件。

等待初始化完成之后,工程目錄下就多了一個(gè) fastlane目錄,其內(nèi)容如下:

咱們來看兩個(gè)主要的,Appfile和Fastfile。

Appfile

Appfile用來存放app_identifier,apple_id和team_id。 了解詳情,它的格式是這樣的:

app_identifier "com.xxx.xxx" # app的bundle identifier
apple_id "xxx@xxx.com" # 你的Apple ID
team_id "XXXXXXXXXX" # Team ID

你也可以為每個(gè)lane(后面會(huì)講到)提供不同的 app_identifier, apple_id 和 team_id,例如:

app_identifier "com.aaa.aaa"
apple_id "aaa@aaa.com"
team_id "AAAAAAAAAA"

for_lane :inhouse do
 app_identifier "com.bbb.bbb"
 apple_id "bbb@bbb.com"
 team_id "AAAAAAAAAA"
end

這里就是為Fastfile中定義的:inhouse設(shè)置單獨(dú)的信息。

Fastfile

Fastfile管理你所創(chuàng)建的 lane ,了解詳情。它的格式是這樣的:

···
# 自動(dòng)更新fastlane 工具
# update_fastlane
#需要的fastlane的最小版本,在每次執(zhí)行之后會(huì)檢查是否有新版本,如果有會(huì)在最后末尾追加新版本提醒
fastlane_version "2.30.1"
#默認(rèn)使用平臺(tái)是 ios,也就是說文件可以定義多個(gè)平臺(tái)
default_platform :ios
platform :ios do
 before_all do
  # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
  cocoapods
 end
 desc "Runs all the tests"
 lane :test do
  scan
 end
 desc "提交一個(gè)新的Beta版本到 Apple TestFlight"
 desc "This will also make sure the profile is up to date"
 lane :beta do
  # match(type: "appstore") # more information: https://codesigning.guide
  gym(scheme: "Docment") # Build your app - more options available
  pilot
  # sh "your_script.sh"
 end
 desc "部署一個(gè)新版本到App Store"
 lane :release do
  # match(type: "appstore")
  # snapshot
  gym(scheme: "Docment") # Build your app - more options available
  deliver(force: true)
  # frameit
 end
 # 你可以定義自己的lane
 #執(zhí)行l(wèi)ane成功后的回調(diào)
 after_all do |lane|
  # slack(
  #  message: "Successfully deployed new App Update."
  # )
 end
 # 如果流程發(fā)生異常會(huì)走這里并終止
 error do |lane, exception|
  # slack(
  #  message: exception.message,
  #  success: false
  # )
 end
end

我們也可以定義一個(gè)自己的lane:

 desc "企業(yè)版"
 lane :inHouse do
 gym(scheme: "XXX",
   export_method:"enterprise",
   output_directory "./build", # 打包后的 ipa 文件存放的目錄
   output_name "XXX" # ipa 文件名
  )
 end

其中一個(gè)lane就是一個(gè)任務(wù),里面是一個(gè)個(gè)的action組成的工作流。

利用目前支持的工具可以做所有包含自動(dòng)化和可持續(xù)化構(gòu)建的每個(gè)環(huán)節(jié),例如:

scan 自動(dòng)化測(cè)試工具,很好的封裝了 Unit Test

sigh 針對(duì)于 iOS 項(xiàng)目開發(fā)證書和 Provision file 的下載工具

match 同步團(tuán)隊(duì)每個(gè)人的證書和 Provision file 的超贊工具

gym 針對(duì)于 iOS 編譯打包生成 ipa 文件

deliver 用于上傳應(yīng)用的二進(jìn)制代碼,應(yīng)用截屏和元數(shù)據(jù)到 App Store

snapshot 可以自動(dòng)化iOS應(yīng)用在每個(gè)設(shè)備上的本地化截屏過程

執(zhí)行

定義完lane之后怎么執(zhí)行呢?打開終端,切換到項(xiàng)目的根目錄:執(zhí)行fastlane lane'name就可以了。成功之后會(huì)在相應(yīng)的路徑下生成ipa文件,如果報(bào)錯(cuò)的話就根據(jù)錯(cuò)誤信息好好查看文檔。

其他

1、這里是官方提供的一些例子。

2、想了解fastlane命令的話可以執(zhí)行$ fastlane –help

3、查看可用任務(wù)的列表,可以執(zhí)行命令$ fastlane lanes

4、fastlane也提供了很多插件方便我們使用,例如pgyer(發(fā)布app到蒲公英)。我們也可以打完包直接傳到蒲公英上,具體的可以看蒲公英提供的文檔。

如果你感覺有些插件不符合自己的情況,你甚至可以自定義插件

5、多個(gè) lane 的話實(shí)際上是可以相互調(diào)用的,這個(gè)其實(shí)特別實(shí)用。例如:

default_platform :ios
platform :ios do
 lane :prepare do
  cocoapods
  match
 end
 desc 'fastlane build'  'fastlane build type:adhoc'
 lane :build do |options|
  # 調(diào)用上面的 prepare 任務(wù)
  prepare
  case options[:type]
  when 'adhoc'
   adhoc
  else
   appstore
  end
 end
 lane : adhoc do
 ···
 end
 lane : appstore do
 ···
 end
end

我們可以在 Fastfile 文件中添加一個(gè)函數(shù)來設(shè)置version號(hào)和build號(hào)。

default_platform :ios

def prepare_version(options)
  increment_version_number(
    version_number: options[:version]
  )
  increment_build_number(
    build_number: options[:build]
  )
end

然后可以在一個(gè)lane中使用這個(gè)函數(shù):

lane :appstore do |options|
  ···
  prepare_version(options)
  ···
end

然后執(zhí)行這個(gè)lane的時(shí)候:

$ fastlane appstore version:2.4.0 build:2.0

關(guān)于“iOS中如何使用Fastlane實(shí)現(xiàn)自動(dòng)化打包和發(fā)布”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.muchs.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

新聞標(biāo)題:iOS中如何使用Fastlane實(shí)現(xiàn)自動(dòng)化打包和發(fā)布-創(chuàng)新互聯(lián)
網(wǎng)頁網(wǎng)址:http://www.muchs.cn/article34/djhgpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、微信公眾號(hào)標(biāo)簽優(yōu)化ChatGPT、網(wǎng)站導(dǎo)航、軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)