自動化打包---fastlane

簡單寫下我使用fastlane的過程,及遇到的問題,希望自己下次在用到fastlane的時候能迅速避坑,希望也能幫助在看文章的你:

我的步驟如下:

1、配置ruby環境:fastlane是基於ruby的,如果你對電腦沒有ruby的話。在這有個小建議:希望你安裝國內的ruby源,因爲如果你用國外的ruby的話,在下面爲工程安裝fastlane時,因爲牆的原因,終端會卡在某個地方

如果你已經安裝了國外的rugy,通過gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/  命令來更換ruby源。

2、安裝xcode命令行工具:xcode-select --install  安裝command line tools

3、安裝fastlane:sudo gem install fastlane

4、初始化fastlane:

  4.1、cd到工程根目錄(創建一個測試工程,名曰test)

  4.2、fastlane init 然後出現一堆

Peter-2:~ Peter$ cd desktop
Peter-2:desktop Peter$ cd Popo/
Peter-2:Popo Peter$ fastlane init
[⠋] 🚀 /Users/peter/.rvm/rubies/ruby-2.4.1/lib/ruby/gems/2.4.0/gems/tty-screen-0.6.4/lib/tty/version.rb:3: warning: already initialized constant TTY::Screen::VERSION
/Users/peter/.rvm/gems/ruby-2.4.1@global/gems/tty-screen-0.6.4/lib/tty/version.rb:3: warning: previous definition of VERSION was here
[✔] 🚀 
[✔] Looking for iOS and Android projects in current directory...
[17:08:01]: Created new folder './fastlane'.
[17:08:01]: Detected an iOS/macOS project in the current directory: 'Popo.xcodeproj'
[17:08:01]: -----------------------------
[17:08:01]: --- Welcome to fastlane 🚀 ---
[17:08:01]: -----------------------------
[17:08:01]: fastlane can help you with all kinds of automation for your mobile app
[17:08:01]: We recommend automating one task first, and then gradually automating more over time
[17:08:01]: 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
?  

輸入4:(自定義)

【注意,如果你沒有用國內的ruby鏡像你很可能卡在 $bundle update這步,1》需要你gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/  命令來更換ruby源 2》需要把Gemfile裏的source "https://rubygems.org"換爲source "https://gems.ruby-china.com"】

初始化完成後悔出現fastlane文件夾,文件夾裏有Appfile和Fastfile兩個文件

5、添加蒲公英測試平臺的插件以供提交測試:

 fastlane add_plugin pgyer 成功後fastlane文件夾下又出現個Pluginfile

6、在此把fastlane文件夾下的文件貼一下

6.1》Pluginfile:

# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!

gem 'fastlane-plugin-pgyer'
 

6.2》Appfile:

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


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

6.3》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 "發佈 蒲公英"
  lane :custom_lane do
     gym(scheme: "test", #工程名
         #workspace: "test.xcworkspace", 示例沒用cocoapods
          export_method: "development",
          output_directory: "/Users/yangyangzi/Desktop/YangZi2/2019/11/自動化打包/fastLane/示例",#導出到的文件夾  隨意創建的文件夾
          silent: true,  # 隱藏沒有必要的信息
          clean: true  # 在構建前先clean
          )
      pgyer(api_key: "17b4fd2e0d086c2a0d888b25c7b84510", 
            user_key: "d0c596ff2b0bdd2acabe29cc6406288a"
            )
  end

  desc "發佈 到 蘋果TestFlight"
    lane :beta_apple do
      gym(scheme: "Test",
          silent: true,  # 隱藏沒有必要的信息
          clean: true  # 在構建前先clean
        )
      pilot #管理TestFlight測試用戶,上傳二進制文件
   end
 
  desc "發佈蘋果商店"
    lane :release_apple do
      
      gym(scheme: "Test", 
          silent: true,  # 隱藏沒有必要的信息
          clean: true  # 在構建前先clean
        )
      deliver #上傳截圖、元數據、App到iTunesConnect
   end


end
 

 

6、執行lane:

執行命令(以打包並分發到蒲公英爲例):fastlane custom_lane即可將ipa傳到蒲公英。

以上便是fastlane的簡單使用,工程地址

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章