fastlane感悟

fastlane感悟

目标:使用fastlane自动打包上传appStore

一、 安装fastlane

fastlane要求Ruby版本,当前最新版本要求ruby版本>=2.1,在安装前有几个准备步骤:

  1. 先查看ruby版本:

    ruby -v

  2. 检查Xcode的CLT是否安装:

    xcode-select --install(如果没有安装,终端会自行安装CLT)

满足以上条件之后,则输入命令安装fastlane

sudo gem install fastlane

简要介绍一下fastlane的工具链:

  • produce 创建可用于 iTunes Connect 和 Apple Developer
  • Portal 的 ios app。
  • cert 自动创建和维护 ios 代码签名证书。
  • sigh 创建、更新、下载和修复 provisioning profiles。
  • snapshot 自动将 App 屏幕截图本地化到每种设备上。
  • frameit 将屏幕截图适配到适当的设备屏幕大小。
  • gym 创建和打包 ios app。
  • deliver 上传屏幕截图、元数据和 App 到 App 商店。
  • pem 自动创建和更新 Push 通知的 profile。

二、初始化fastlane

进入项目目录之后,输入命令:

fastlane init

初始化时,会出现4个选项:

  1. Automate screenshots(自动化截图)
  2. Automate beta distribution to TestFlight(TestFlight)
  3. Automate App Store distribution(appStore发布版本)
  4. Manual setup - manually setup your project to automate your tasks(自定义)

初始化完成后,会出现fastlane文件夹,包含:

  • Appfile,用于存放app ID和开发者的Apple ID
  • Fastfile,用于管理创建的lane,lane则可以调用各个action(即fastlane的工具链)
  • Snapfile,用于指定需要进行屏幕截图的设备类型(根据选项生成,可自己创建文件用于配置)
  • Deliverfile,用于配置发布至appStore的文件(根据选项生成,可自己创建文件用于配置)

配置到处文件的编码格式为UTF-8

/.bashrc,/.bash_profile,~/.zshrc文件中,编辑添加

export LC_ALL=en_US.UTF-8

export LANG=en_US.UTF-8

在fastlane文件夹同级的目录下,新建Gemfile文件,加入配置:

source "https://rubygems.org"

gem "fastlane"

然后在命令行中执行

[sudo] bundle update

通过Gemfile和Gemfile.lock进行版本控制,之后则可以开始配置Fastfile了,配置完成之后,执行

bundle exec fastlane [lane]

三、配置fastlane

附上官网链接: https://docs.fastlane.tools/actions/

所有的配置都可以写在Fastfile文件里,工具链可以自行生成文件进行,在Fastfile里调用一下即可,例如:Deliverfile里面写了配置上传appStore的一些配置项,在Fastfile中,lane调用一下deliver则引用了
Deliverfile中的配置

当已有Fastfile需要导入时,输入命令

import './path/to/other/Fastfile'

fastlane配置很多,可以通过官网查看文档,每个aciton都有相应的参数配置,接下来列举一下常用的action的插件以及相应的工具链:

Testing 测试

  • scan run_tests的别名

  • slather 使用slather来生成一个代码覆盖率报告

  • swiftlint 使用SwiftLint运行swift代码验证

  • xcov 写的不错的代码的覆盖率报告

  • sonar 以编程方式调用sonar-scanner分析SonarQube

  • oclint 通过OCLint进行Lints的实现

  • gcovr Xcode项目运行测试覆盖率报告

  • lcov 使用lcov生成覆盖率数据

  • appium Appium用RSpec运行UI测试

  • xctool 使用xctool运行测试

  • xcode_server _get _assets 下载Xcode Bot的xcarchive和日志

  • run_tests 简单地运行你的iOS应用程序(通过scan)

Building 打包

  • gym build_ios _app的别名

  • cocoapods 相当于pod install

  • gradle 所有相关的action,包括构建和测试Android应用

  • clear_derived _data 删除 Xcode Derived 缓存

  • adb Run ADB Actions

  • xcversion 选择一个Xcode来使用版本说明符

  • xcodebuild 使用xcodebuild命令来构建和签名应用程序

  • carthage Runs carthage for your project

  • xcode_select 更改使用的Xcode路径。用于Xcode的beta版本

  • ensure_xcode _version 确保选中的Xcode版本与Xcode select匹配一个值

  • clean_cocoapods _cache 删除pods的缓存

  • verify_xcode 验证Xcode的安装是否正确

  • xcode_install 确保安装了Xcode的某个版本

  • verify_pod _keys 验证从podFile中引用的所有键都是非空的

  • build_android _app gradle分级的别名

  • xcarchive 使用xcodebuild归档项目

  • xcclean 使用xcodebuild清理项目

  • build_app build_ios _app的别名

  • xcbuild 使用xcodebuild构建项目

  • spm 在项目中运行Swift包管理器

  • build_ios _app 简单地构建和签署应用程序(gym的别名)

  • xcexport 使用xcodebuild导出项目

  • xctest 在给定的模拟器上运行测试

Screenshots 截图

  • snapshot capture_ios _screenshots的别名

  • screengrab capture_android _screenshots的别名

  • frameit frame_screenshots的别名

  • frame_screenshots Adds device frames around all screenshots (via frameit)

  • capture_android _screenshots Automated localized screenshots of your Android app (via screengrab)

  • capture_ios _screenshots Generate new localized screenshots on multiple devices (via snapshot)

  • capture_screenshots capture_ios_screenshots的别名

Project 项目配置

  • increment_build _number 项目的build number自增

  • set_info _plist _value Sets value to Info.plist of your project as native Ruby data structures

  • get_version _number Get the version number of your project

  • get_info _plist _value Returns value from Info.plist of your project as native Ruby data structures

  • update_info _plist Update a Info.plist file with bundle identifier and display name

  • update_app _identifier Update the project's bundle identifier

  • get_build _number Get the build number of your project

  • increment_version _number Increment the version number of your project

  • update_project _team Update Xcode Development Team ID

  • update_app _group _identifiers This action changes the app group identifiers in the entitlements file

  • get_ipa _info _plist _value Returns a value from Info.plist inside a .ipa file

  • recreate_schemes Recreate not shared Xcode project schemes

  • update_url _schemes Updates the URL schemes in the given Info.plist

  • set_build _number _repository Set the build number from the current repository

  • set_pod _key Sets a value for a key with cocoapods-keys

Releasing your app 发布

  • deliver Alias for the upload_to_app_store action

  • supply Alias for the upload_to_play_store action

  • appstore Alias for the upload_to_app_store action

  • upload_to_play_store Upload metadata, screenshots and binaries to Google Play (via supply)

  • upload_to_app_store Upload metadata and binary to iTunes Connect (via deliver)

四、运行时报错

当出现类似fastlane gym produces error: method `to_plist' not defined in Array的报错情况时,建议移除fastlane,重新安装fastlane

rvm @global do gem uninstall fastlane 
rvm all do gem uninstall fastlane
gem uninstall fastlane
gem install fastlane

你可能感兴趣的:(fastlane感悟)