• Mac ~ fastlane安装使用说明


    fastlane安装使用说明

    • 环境检测

    因为fastlane是ruby书写的,所以需要检测当前ruby的版本, 需要保证ruby的版本在2.0以上,在终端输入以下命令:

    $: ruby -v (# or  `ruby --version`)
    

    如果ruby低于2.0.需要进行以下步骤:

    $:rvm remove versionNumber (#versionNumber是通过上述命令得出的当前Mac的ruby版本号)
    
    $:rvm list known  (#列出已知可用的ruby版本号)
    
    $:rvm install  versionNumber (#versionNumber是需要安装的ruby版本号)
    
    • fastlane配置

    需要安装Xcode,命令行安装需要执行终端输入:

    xcode-select --install
    

    继续安装fastlane,有两种方式,第一种通过RubyGems安装:

    sudo gem install fastlane -NV
    

    第二种通过HomeBrew:

    brew cask install fastlane
    
    • set up Environment variables(配置环境参数)

    显示mac系统的隐藏文件,点按cmd + shift + . 三个按钮,显示user级别下的隐藏文件,找到 .bash_profile进行编辑。

    <1> 可以通过拖动此文件到快捷栏上的Xcode图标上会自己打开,也可以通过终端vi .bash_profile来进行编辑。编辑方式在此文件中添加以下配置

    export LC_ALL=en_US.UTF-8
    
    export LANG=en_US.UTF-8
    

    <2>: 对于电脑是没有.bash_profile文件(,这种情况需要手动创建bash_profile文件,终端cd到macUser(用户名)文件下(或者直接打开或者command+T另开一个终端界面),逐步输入以下命令:

    $: touch .bash_profile
    $:vi .bash_profile (#也可使用open .bash_profile)
    

    打开bash_profile后,添加<1>中的命令。

    • 使用Gemfile

    其实这步不用,管网给出的文档说,Gemfile是通过需要手动终端输入命令生成的,但是fastlane init之后显示是直接连带生成,其中给出了两句代码如下:

    source "[https://rubygems.org](https://rubygems.org/)"
    
    gem "fastlane"

    项目中使用自动化打.ipa包

    1,对于fastlane配置好之后,可以开始对工程目录进行使用。

    cd到对应的项目工程下,继续终端输入:

    fastlane init
    

    会看到生成至少包含fastfile和Appfile的fastlane文件和Gemfile文件。 其中会出现4个选项,1-2-3会涉及到需要登录账号和密码操作.

    • Appfile: 用来存储一些公共信息,比如app_identifier、apple_id、team_id、itc_team_id等。

    • fastfile: 用来定义所有的lane任务。

    • Gemfile: 管理fastlane的工具,类似pod.lock。

    2, 对fastlane进行任务定义coding。

    默认是iOS平台,输入命令可以修改。

    默认的生成的fastlane模板是:

    default_platform(:ios)
    
    platform :ios do
    
      desc "Description of what the lane does"
    
      lane :custom_lane do
    
        # add actions here: [https://docs.fastlane.tools/actions](https://docs.fastlane.tools/actions)
    
      end
    
    end

    custom_lane即如函数名一样,终端输入fastlane custom_lane即可执行此lane当前最小定义域内do{...}end中的行为。

    <1>: 定义lane。
    
    >>>get_certificates #获取证书
    
    >>>get_provisioning_profile #获取描述文件
    
    >>>sigh(adhoc:false)
    
    >>>build_app(workspace: "Sakura.xcworkspace", scheme: "Sakura") //假如你使用了cocoapod
    
    >>>upload_to_app_store(skip_metadata: true, skip_screenshots: true) //上传到appStore
    
    >>>changelog = prompt(
    
                 text: "Changelog: ",///提交change的日志信息
    
                multi_line_end_keyword: "END",///当想结束本次信息输入时,输入END点按Enter键即可
    
        )
    
    >>>upload_to_testflight(changelog: changelog) //上传到testflight进行测试
    
    eg:  upload_to_testflight(changelog: "Add rocket emoji")
    
    eg: upload_to_testflight(skip_waiting_for_build_processing: true) 
    
          skip the "Waiting for processing" of the binary
    
          While this will speed up your build, it will not distribute
    
          the binary to your tests, nor set a changelog
    
    通过以下命令,可以实现在p12授权的情况下,进行自动打.ipa包,这里以Sakura为例
    
    >>>build_app(
    
            workspace: "Sakura.xcworkspace", #使用了cocoapod就需要有workspace了
    
            scheme: "Sakura",   #工程下要打包的项目,如果一个工程有多个项目则用[项目1,项目2]
    
            configuration: "Release",              # Debug or Release
    
            clean: true,                           #清空上次打包信息
    
            export_method:"enterprise",        # app-store, ad-hoc, package, enterprise, development, developer-id
    
            output_directory: './build',  #指定ipa最后输出的目录
    
            output_name: "Sakura.ipa",
    
    //export_xcargs: "-allowProvisioningUpdates",  
    
            export_options: {
    
                provisioningProfiles: {
    
                    "当前scheme对应的target工程的bundle id" => "当前scheme所对应的profile描述文件",
    
                }
    
            }
    
        )
    
    >>>enable_automatic_code_signing(path: "Sakura.xcworkspace") //开启自动签名
    

    fastlane添加插件

    1,搜索插件,可以通过以下命令(默认是在当前工程目录下,以firim(与蒲公英并列的主流分发平台之一) 为例):

    $:fastlane search_plugins fir

    实际的要安装的插件是firim,因此搜索的结果会展示多个包含多个fir的插件名,当看到firim的时候,可以锚定即是它(fir.im)。

    2,添加插件

    $:fastlane add_plugin firim 在这一步,会出现以下错误:

    An error occurred while installing unf_ext (0.0.7.6), and Bundler cannot
    continue.
    Make sure that `gem install unf_ext -v '0.0.7.6'` succeeds before bundling.
    

    把Gemfile文件的source注释即可。

    3,在fastlane中添加插件命令

    上传ipa到fir.im服务器,在fir.im获取firim_api_token

    firim(firim_api_token: '123456fdedftyuioopa9988hnai9')
    

    如果是上传到蒲公英,需要再蒲公英获取api_key和userKey(登录成功,点击Api信息)

    pgyer(api_key: "2bd73d92030", user_key: "f0c61905ed")

    查询更多参数

    当已知的某个ruby命令中参数不能够功能时,可以使用

     fastlane action **** 
    //such as 'upload_to_testflight', to get a list of all available options
    fastlane action upload_to_testflight

    "当前scheme所对应的profile描述文件名"指当前工程在打包的时候非自动配置时需要选择的此profile文件。

    一个项目在发布时,bundleid对应的Provisioning Profiles会存在多个,有效即可。

    当选择Automatically manage signing的时候,需要cd到~/Library/Mobile Device/profile文件夹中找对应有效的描述文件。

    如果一个工程中存在多个target会有多个Provisioning Profiles同时存在。则需要在fastlane文件定义环境变量或手动切换进行选择Provisioning Profiles。

  • 相关阅读:
    跨站请求伪造 CSRF
    通过反射动态调用外部托管Dll
    Effective TestStand Operator Interfaces
    DataTable转成实体列表 和 DataRow转成实体类
    NI LabVIEW 编程规范
    TestStand 界面重置【小技巧】
    TestStand 基本知识[1]--基本配置
    泛型 List转换成DataTable
    如何修改数据库的服务器排序规则
    3个N加上各种运算符号结果等于6(纯属娱乐)C#
  • 原文地址:https://www.cnblogs.com/liuxiaokun/p/12735233.html
Copyright © 2020-2023  润新知