FastLane+蒲公英执行脚本自动打包

如果报任何奇奇怪怪的问题,就使用gem将相关的工具卸载,我就报了一个不管打什么环境的包都会用distribution的配置文件,很是费解,卸载重装就没问题了

0、移除

gem list #查找对应的工具
gem uninstall #移出对应的工具

1、安装xcode命令行工具

xcode-select --install

如果没有安装,会弹出对话框,点击安装。
如果提示xcode-select: error: command line tools are already installed, use "Software Update" to install updates表示已经安装

2、安装Fastlane

sudo gem install fastlane -NV#可能因为网速问题,最好使用自己的手机个人热点

3、检验版本

fastlane --version #fastlane 2.102.0

4、打包到蒲公英

蒲公英相关配置查看蒲公英文档

sudo fastlane add_plugin pgyer

5、初始化Fastlane

cd到你的项目目录执行

fastlane init 

6、配置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 "Push a new release build to the App Store"
  #lane :release do
    #build_app(workspace: "HBCGAPP.xcworkspace", scheme: "HBCGAPP")
    #upload_to_app_store
  #end
#end


#fastlane_version "2.57.2"

default_platform :ios

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

 # 测试环境
 lane :Dev do
    gym(
    scheme: "HBCGAPP", # Build your app - more options available
    clean:true, # 在构建前先clean
    configuration: "Debug",  # 配置为Release版本
    export_method:"development",
    output_directory: "/Users/anxianglong/Desktop/测试包",
    export_xcargs: "-allowProvisioningUpdates"
    ) 
    #pgyer(api_key: "xxxxxxxx", user_key: "xxxxxx", update_description: "测试环境")
    firim(firim_api_token:"b071288f8edec1bd9fa8226baa02188d")
  end

 # 预发环境
 lane :Ent do
    gym(
    scheme: "HBCGAPP", 
    clean:true, 
    configuration: "Release", 
    export_method:"enterprise",
    output_directory: "/Users/anxianglong/Desktop/测试包",
    export_xcargs: "-allowProvisioningUpdates"
    ) 
    #pgyer(api_key: "xxxx", user_key: "xxxx", update_description: "预发环境")
   firim(firim_api_token:"b071288f8edec1bd9fa8226baa02188d")
  end

 # 正式环境测试版本
 lane :Adh do
    gym(
    scheme: "xxxx", 
    clean:true, # 在构建前先clean
    configuration: "Release",  # 配置为Release版本
    export_method:"ad-hoc",
    output_directory: "/Users/xxxxxx/Desktop/IPA",
    export_xcargs: "-allowProvisioningUpdates"
    ) 
    pgyer(api_key: "xxxx", user_key: "xxxxx", update_description: "正式环境")
    #firim(firim_api_token:"xxxx")
  end

  # 正式环境AppStore版本
  lane :App do
    gym(
    scheme: "xxxx", # Build your app - more options available
    clean:true, # 在构建前先clean
    configuration: "Release",  # 配置为Release版本
    export_method:"app-store",
    output_directory: "/Users/xxxx/Desktop/IPA",
    export_xcargs: "-allowProvisioningUpdates"
    )
  deliver(force: true)
  end

  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

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

7、打包

fastlane Dev

8、多参数

fastlane Dev appversion:100 buildNumber:111

fastlane文件

 # 测试环境 
 lane :Dev do |options| 

    # build:options[:build]
    # increment_build_number

    # get_info_plist_value
  
  set_info_plist_value(path: "HBCGAPP/Info.plist", key: "CFBundleShortVersionString", value: options[:appversion])
  set_info_plist_value(path: "HBCGAPP/Info.plist", key: "CFBundleVersion", value: options[:buildNumber])
  

    gym(
    scheme: "HBCGAPP", # Build your app - more options available
    workspace: "HBCGAPP.xcworkspace",
    clean:true, # 在构建前先clean
    xcargs: 'DEBUG_INFORMATION_FORMAT="dwarf-with-dsym"',
    configuration: "Debug",  # 配置为Release版本
    export_method:"development",
    output_directory: "~/Desktop/打包",
    export_xcargs: "-allowProvisioningUpdates",
      include_symbols:true,
      output_name: 'HBCGAPP' + ' ' + Time.now.strftime('%Y-%m-%d %H:%M')
    )

    #pgyer(api_key: "xxxxxxxx", user_key: "xxxxxx", update_description: "测试环境")
    pgyer(api_key: "***", user_key: "***", update_description: "测试环境")
  end

你可能感兴趣的:(FastLane+蒲公英执行脚本自动打包)