ios专题iOS开发

fastlane自动化构建工具

2018-04-08  本文已影响25人  HeavenWong

一句代码fastlane [lane_name],实现一键自动完成构建打包。fastlane还有很多其他功能,学会直线骑车再学拐弯等骑车技巧就很容易了。下面讲fastlane简单的自动化构建,免除我们日常工作中的编译、打包、部署等重复流程。

一、安装fastlane

// 报错的大致信息:
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).
ERROR:  SSL verification error at depth 1: unable to get local issuer certificate (20)
...
ERROR:  Error installing fastlane:
    ERROR: Failed to build gem native extension.

    Building has failed. See above output for more information on the failure.
extconf failed, exit code 1

// 安装新版本,这个版本没问题,rvm>2.0版本就可以了
rvm install 2.2.2

回到正题:安装fastlane


fastlane官方地址
[fastlaneGithub地址]
参考文章1
参考文章2
参考LuisX
参考文章4

// 终端键入,等待安装完成
rvm install fastlane

// 终端键入
fastlane -v

二、fastlane简单使用和初始化

cd 你项目的根目录
fastlane初始化.png
Appfile
Fastfile
实现企业版自动化构建配置,解决上面权限问题
desc "企业版"
  lane :inhouse do
  gym(scheme: "BeeEnrichmentAppiOS",
  clean:true,
  configuration: "Release",
  export_method: "enterprise",
  output_name:"BeeEnrichmentAppiOS",
  output_directory:"build") # Build your app - more options available
  deliver(force: false)
  # frameit
  end
fastlane actions:      列出所有可用fastlane活动
fastlane action [action_name]:   显示一个更详细的活动描述
fastlane lanes:      列出所有可用lanes (有描述)
fastlane list:       列出所有可用lanes (没有描述)
fastlane new_action:     在fastlane创建一个活动(集成)

三、gym配置自动化构建

// 终端
sudo gem install gym

一下操作都是cd到项目的根目录下

// 终端
gym --workspace "gymTest.xcworkspace" --scheme "gymTest" --clean
// 或者用这条命令,fastlane 指令
fastlane gym
执行
platform :ios do

  before_all do
  # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
  cocoapods
  end

  #执行lane成功后的回调
  after_all do |lane|
   # slack(
   #  message: "Successfully deployed new App Update."
   # )
     end
  # 如果流程发生异常会走这里并终止
  error do |lane, exception|
   # slack(
   #  message: exception.message,
   #  success: false
   # )
     end
  end

  desc "Description of what the lane does"
  lane :custom_lane do
    # add actions here: https://docs.fastlane.tools/actions
  end

  desc "提交一个新的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: "你的项目名字") # Build your app - more options available
  pilot
  # sh "your_script.sh"
  end

  desc "部署一个新版本到App Store"
  lane :release do
  # match(type: "appstore")
  # snapshot
  gym(scheme: "你的项目名字”,
      clean:true,
      configuration: "Release”,
      export_method: "appstore"
      ) # Build your app - more options available
  deliver(force: false)
  # frameit
  end
  
  desc "企业版"
  lane :inhouse do
  gym(scheme: "你的项目名字",
      clean:true,
      configuration: "Release",
      export_method: "enterprise",
      output_name:"你的项目名字",#打包.ipa的文件名
      output_directory:"build") # Build your app - more options available
  deliver(force: false)
  # frameit
  end

end

自动打包成功.png
上一篇 下一篇

猜你喜欢

热点阅读