自动化打包---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("278432876@qq.com") # 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的简单使用,工程地址

 

 

 


版权声明:本文为denggun12345原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。