Fastlane安裝和使用和注意事項

Fastlane安裝和使用參考博客:http://www.itdecent.cn/p/840943eff17b
http://www.cocoachina.com/ios/20170519/19317.html

xcode-select --install

ruby -v查看ruby版本,要求2.0及以上版本

ruby的鏡像文件路徑改為https://gems.ruby-china.org/

gem sources --remove https://ruby.taobao.org/

gem sources --add https://rubygems.org

gem sources -l

安裝:
sudo gem install fastlane -NV

配置fastlane:切換目錄到包含xxx.xcodeproj的項目目錄下輸入
fastlane init
輸出:

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

選擇第四個后一路回車即可(等待時間略長),結束后會看到生成了fastlane目錄,該目錄包含Appfile和Fastfile;

此時不關終端,過一會兒提示回車,看提示回車幾次之后結束;

[15:37:00]: Continue by pressing Enter ?

[15:37:05]: ------------------------------
[15:37:05]: --- Where to go from here? ---
[15:37:05]: ------------------------------
[15:37:05]: ??  Learn more about how to automatically generate localized App Store screenshots:
[15:37:05]:         https://docs.fastlane.tools/getting-started/ios/screenshots/
[15:37:05]: ?????  Learn more about distribution to beta testing services:
[15:37:05]:         https://docs.fastlane.tools/getting-started/ios/beta-deployment/
[15:37:05]: ??  Learn more about how to automate the App Store release process:
[15:37:05]:         https://docs.fastlane.tools/getting-started/ios/appstore-deployment/
[15:37:05]: ?????  Lern more about how to setup code signing with fastlane
[15:37:05]:         https://docs.fastlane.tools/codesigning/getting-started/
[15:37:05]: 
[15:37:05]: To try your new fastlane setup, just enter and run
[15:37:05]: $ fastlane custom_lane
LYPC:dingdingbao 4 LYPC$ 

然后(二選一,可以使用命令bundle exec fastlane custom_lane代替fastlane custom_lane,這樣會執(zhí)行的更快):fastlane custom_lane
bundle exec fastlane custom_lane
輸出:

[15:40:15]: ------------------------------
[15:40:15]: --- Step: default_platform ---
[15:40:15]: ------------------------------
[15:40:15]: Driving the lane 'ios custom_lane' ??

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
+------+------------------+-------------+

[15:40:15]: fastlane.tools finished successfully ??  這句表示執(zhí)行成功
LYPC:dingdingbao 4 LYPC$ 

打開Fastfile文件:打包是最主要的一步fastlane中有專門用于編譯、打包的命令gym,我們加到lane :custom_lane do后看看會不會有問題
export_method:可選的值有:app-store、ad-hoc、development、enterprise

根據(jù)提示來輸入Apple ID(開發(fā)者賬號 、密碼也會讓輸入)及app_identifier(就是項目的bundle id)等信息
這期間我使用的是企業(yè)版(299$)的賬號 登錄不成功 不知道原因 難道企業(yè)版不能使用fastlane嗎 換了一個99$賬號 可以了.

出現(xiàn)下面的提示 沒有問題你就輸入 y:

Please confirm the above values (y/n)

然后去看路徑下多出來的fastlane文件:

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

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管理你所創(chuàng)建的 lane

* scan 自動化測試工具,很好的封裝了 Unit Test
* sigh 針對于 iOS 項目開發(fā)證書和 Provision file 的下載工具
* match 同步團隊每個人的證書和 Provision file 的超贊工具
* gym 針對于 iOS 編譯打包生成 ipa 文件
* deliver 用于上傳應用的二進制代碼,應用截屏和元數(shù)據(jù)到 App Store
* snapshot 可以自動化iOS應用在每個設備上的本地化截屏過程

這個是查到的比較全的帶解釋的:

# 指定 fastlane 最小版本
fastlane_version "2.20.0"

# 指定當前平臺,可以設置為 ios 、android、mac
default_platform :ios

platform :ios do

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

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

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

    # 最重要的打包命令
    gym(
              export_method: 'ad-hoc',        # 打包的方式,可設置為 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的最小版本,在每次執(zhí)行之后會檢查是否有新版本,如果有會在最后末尾追加新版本提醒
fastlane_version "2.30.1"
default_platform :ios
platform :ios do
  before_all do
  end
  lane :beta do |options|
  cocoapods
  build_app(export_method: "ad-hoc")
  pgyer(api_key: "3335fc51738d0e016e876f877dab041a", user_key: "69b1831d78c147766e643e8d4a006bb3")
  end

  after_all do |lane|
    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end

編輯好以上內容,打開終端執(zhí)行:
fastlane buildDebugApp version:2.2.0
或者fastlane buildDebugApp
這個過程會需要一些時間, 如果是直接傳到iTunes connect上 這個也會把版本號校驗出來,提示你確定版本號的正確否。

執(zhí)行結束后我們在當前目錄下將會看到[ProductName].ipa文件。

報錯:
[!] Add 'gem "cocoapods"' to your Gemfile and restart fastlane
修改Gemfild文件 里面的 gem 'fastlane' 為 gem "cocoapods"

報錯: method `to_plist' not defined in Array
分別執(zhí)行以下命令:rvm @global do gem uninstall fastlane
rvm all do gem uninstall fastlane
gem uninstall fastlane
gem install fastlane

然后在執(zhí)行打包(成功則萬事大吉)依舊報錯的話:[08:50:55]: RubyGems is not listed as your Gem source
[08:50:55]: You can run gem sources to see all your sources
[08:50:55]: Please run the following command to fix this:
[08:50:55]: $ gem sources --add https://rubygems.org
更改gem源:gem sources查看當前是啥
修改:gem sources --add https://rubygems.org然后gem sources查看確認一下是否修改成功

重新執(zhí)行打包:fastlane  buildDebugApp
成功后輸出:
[09:07:26]: Upload success. Visit this URL to see: https://www.pgyer.com/6DFV

+------+---------------------+-------------+
|             fastlane summary             |
+------+---------------------+-------------+
| Step | Action              | Time (in s) |
+------+---------------------+-------------+
| 1    | Verifying fastlane  | 0           |
|      | version             |             |
| 2    | default_platform    | 0           |
| 3    | cocoapods           | 6           |
| 4    | build_app           | 187         |
| 5    | pgyer               | 17          |
+------+---------------------+-------------+

[09:07:26]: fastlane.tools finished successfully ??

#######################################################################
# fastlane 2.86.2 is available. You are on 2.86.1.
# You should use the latest version.
# Please update using `sudo gem install fastlane`.
#######################################################################

2.86.2 Fixes get_version_number to auto-select target when there is only one
* Fixes get_version_number to auto-select target when there is only one (#12121) via Josh Holtz

Please update using `sudo gem install fastlane`
LYPC:StarCar LYPC$ 
  • 企業(yè)版的fastlane打包,還未找到原因 總是Apple ID登錄不成功?。。?!如果有做成功的秋跪求指導。
    這中間歷經磨難才調整好,現(xiàn)在回想起來也沒那么坎坷,很容易就集成好了,各位看官有什么自己的想法和優(yōu)秀建議 多多交流。
附上一個友情鏈接:
中間會遇到的情況 升級配置:
使用RVM也就是Ruby Version Manager,Ruby版本管理器來升級ruby,RVM包含了Ruby的版本管理和Gem庫管理(gemset)
安裝RVM: curl -L get.rvm.io | bash -s stable

source ~/.bashrc

source ~/.bash_profile

rvm -v

使用RVM升級Ruby
ruby -v

列出已知ruby的版本,會出現(xiàn)很多平臺不同的ruby的版本, 找到自己需要的版本
rvm list known

rvm install 2.1.10

查詢:rvm list
卸載:rvm remove 2.0.0


設置默認版本: rvm use 2.1.10 --default

ruby -v   看看版本有沒有變化PS:首先說明一下,在這一步,需要按回車鍵,連續(xù)按幾次,當然如果你沒裝xcode,需要先去裝xcode,不然會報錯,接下來愉快的使用ruby吧
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容