iOS 使用 Fastlane 一鍵打包

iOS 使用 Fastlane 上傳 App 到蒲公英

1.安裝Fastlane

三選一
sudo gem install fastlane
sudo gem install fastlane -NV
brew cask install fastlane

2.安裝shenzhen

sudo gem install shenzhen

3.在xcodeproj文件同級目錄下,執(zhí)行

fastlane init

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
?  
1. 自動截屏。這個功能能幫我們自動截取APP中的截圖,并添加手機邊框(如果需要的話),我們這里不選擇這個選項,因為我們的項目已經(jīng)有圖片了,不需要這里截屏。
2. 自動發(fā)布beta版本用于TestFlight,如果大家有對TestFlight不了解的,可以參考王巍寫的這篇文章
3. 自動的App Store發(fā)布包。我們的目標是要提交審核到APP Store,按道理應該選這個,但這里我們先不選,因為選擇了以后會需要輸入用戶名密碼,以及下載meta信息,需要花費一定時間,這些數(shù)據(jù)我們可以后期進行配置。
4. 手動設(shè)置。

這里我們選擇4后一路回車即可,結(jié)束后會在工程文件目錄中看到生成了fastlane文件,該目錄包含Appfile和Fastfile;

4.設(shè)置Appfile文件內(nèi)容:

Appfile用來存放app_identifier,apple_id和team_id:
有多個的時候 可以for_lane這樣添加多個;

# app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app
# apple_id("[[APPLE_ID]]") # Your Apple email address

# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile

app_identifier "com.****.****"      # bundleId
apple_id "*******@outlook.com"      # 蘋果賬號
team_id "*******"               # 團隊ID

for_lane :inhouse do
  app_identifier "com.****.****"        # bundleId
  apple_id "*******@outlook.com"        # 蘋果賬號
  team_id "*******"             # 團隊ID
end

5.設(shè)置Fastfile文件內(nèi)容:

Fastfile管理你所創(chuàng)建的 lane
上面這個是網(wǎng)上查到的解釋,下面的一個是我自己給項目配的

# 指定 fastlane 最小版本
fastlane_version "2.20.0"
# 指定當前平臺,可以設(shè)置為 ios 、android、mac
default_platform :ios

platform :ios do
# 在執(zhí)行每一個 lane 之前都先執(zhí)行這個代碼
  before_all do
  end

# 定義一個創(chuàng)建測試包的 lane
# 我們調(diào)用的命令就是調(diào)用 fastlane 的 lane
  lane :buildDebugApp do |op|
      # 根據(jù)輸入的版本設(shè)置項目 version number (我們初始化 fastlane 的時候是在 .xcworkspace 目錄下, 而我們的項目中 ,.xcworkspace 和 .xcodeproj 不在同一級目錄,這里的“increment_version_number”需要檢測 .xcodeproj 項目文件,所以需要指定該文件的目錄)
    increment_version_number({xcodeproj: './HomeMate2_Trunk/HomeMate.xcodeproj', version_number: op[:version]})

    # 根據(jù)輸入的版本設(shè)置項目 build number (同上,也是需要指定 .xcodeproj 的目錄)
    increment_build_number({xcodeproj: './HomeMate2_Trunk/HomeMate.xcodeproj', build_number: op[:version]})

    # 最重要的打包命令
    gym(
              export_method: 'ad-hoc',        # 打包的方式,可設(shè)置為 appstore(默認),enterprise
                     scheme: "HomeMate",    # 指定需要打那個 scheme 的包
                  workspace: "HMWorkSpac.xcworkspace",    # 指定打包的項目文件
                output_name: "HomeMate.ipa",      # 打包輸出名稱
                     silent: true,    # 隱藏不必要信息
                      clean: true,    # 打包前是否 clean 項目
              configuration: "Debug",    # 配置為 debug 版本
              buildlog_path: "./fastlanelog",    # 日志輸出目錄
       codesigning_identity: "iPhone Developer: Hailiang He (xxxxxxxxxx)",       # 代碼簽名證書
           output_directory: "/Users/xxx/Desktop"     # ipa輸出目錄
     )
  end

  # 在執(zhí)行每一個 lane 之后執(zhí)行該功能
  after_all do |lane|
  end

  # 在執(zhí)行每一個 lane 出錯的時候執(zhí)行該功能
  error do |lane, exception|
  end

end

我的項目↓

# 指定 fastlane 最小版本
fastlane_version "2.20.0"
# 指定當前平臺,可以設(shè)置為 ios 、android、mac
default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"

  lane :enterprise do      #分號后面不能有空格
    gym(
      scheme:"enterprise",
     #export_method:可選的值有:app-store、ad-hoc、development、enterprise
      export_method:"enterprise",      #打包的類型,我打的是企業(yè)包
      output_directory:"/Users/***/Desktop",    #打包出來的地址
      output_name:"enterprise_***.ipa",      #打包好的文件名
      export_xcargs: "-allowProvisioningUpdates",
    )
  end

#  lane :custom_lane do
#    # add actions here: https://docs.fastlane.tools/actions
#    export_method:development
#  end

end

6.打包成ipa

保存之后在終端里面運行 三選一
fastlane enterprise
fastlane ios enterprise
fastlane enterprise version:2.2.0
就會開始打包了。

7.參考資料

iOS Fastlane自動化打包(1) 安裝和打包IPA
Fastlane安裝和使用和注意事項
使用fastlane實現(xiàn)iOS持續(xù)集成

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容