fastlane自动打包发布

2018-12-10  本文已影响10人  light_of_king

一、安装
需要MacOS 环境

二、使用

iOS

三、实际使用


附录

# 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)

$env="sit" # uat sit pro
$kAppId="A" # A B
$buildPlatform="phone" # phone pad

platform :ios do
    desc "all lane actions"
    lane :all do
        # increment_build_number
        # increment_version_number
        increment_version_number(
            version_number: "0.0.9" # Set a specific version number
        )
        increment_build_number(
          build_number: get_version_number().gsub(/\./,"").gsub(/^0+/,"") # set a specific number
        )
        build(env:"sit",kAppId:"A",buildPlatform:"phone")
        build(env:"sit",kAppId:"A",buildPlatform:"pad")
        #install
    end
    desc "set environment"
    lane :setConfig do |options|
        $env ||= options[:env]
        $kAppId ||= options[:kAppId]
        $buildPlatform ||= options[:buildPlatform]
        getConfig
    end
    desc "get environment"
    lane :getConfig do
        puts "environment   : #{$env.upcase}"
        puts "kAppId        : #{$kAppId}" + ($kAppId=="A" ? "A" : "B")
        puts "buildPlatform : I#{$buildPlatform.capitalize}"
    end
    desc "build app"
    lane :build do |options|
        if options
            setConfig(options)
        end
        # add actions here: https://docs.fastlane.tools/actions
        # this is UAT environment
        # set package  A B
        set_info_plist_value(
            path: "./Platform_Mobile/Info.plist", 
            key: "kAppId", 
            value: $kAppId
        )
        # update for info.plist
        update_info_plist( # update app identifier string
            plist_path: "./Platform_Mobile/Info.plist",
            app_identifier: "com.package.name#{$env}",
            display_name: "APPNAMEI#{$buildPlatform.capitalize}_#{$env.upcase}"
        )
        # build setting key-values
        # APP Icon资源图
        # ASSETCATALOG_COMPILER_APPICON_NAME=AppIcon
        # 首屏资源图
        # ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME=LaunchImage
        # 运行设备 iPhone为"1",iPad为"2"
        # TARGETED_DEVICE_FAMILY=1
        # ASSETCATALOG_COMPILER_APPICON_NAME="" ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME=""
        output_name = ($kAppId=="A" ? "A" : "B") + "_" + $env.upcase + "_I" + $buildPlatform.upcase + "_V" + get_build_number + ".ipa"
        appIcon = $env == "sit" ? "AppIcon" : ""
        launchImage = $env == "sit" && $buildPlatform == "phone" ? "LaunchImage" : ""
        deviceFamily = $buildPlatform == "phone" ? "1" : "2"
        xcargs = $buildPlatform = %Q{TARGETED_DEVICE_FAMILY=#{deviceFamily} ASSETCATALOG_COMPILER_APPICON_NAME=#{appIcon} ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME=#{launchImage}}
        build_ios_app(
            workspace: "Platform_Mobile.xcworkspace",
            # error : You can only pass either a 'workspace' or a 'project', not both
            # project: "Platform_Mobile.xcodeproj",
            scheme: "Platform_Mobile",
            # configuration: "Release",
            export_method: "enterprise", # app-store,ad-hoc,package,enterprise,development,developer-id
            # silent: true,
            # clean: true,
            output_directory: "./build/", # Destination directory. Defaults to current directory.
            output_name: output_name,       # specify the name of the .ipa file to generate (including file extension)
            # sdk: "iOS 11.1"        # use SDK as the name or path of the base SDK when building the project.
            export_xcargs: "-allowProvisioningUpdates",
            suppress_xcode_output: true,
            xcargs: xcargs,
            export_options: {
                allowProvisioningUpdates: true,
                provisioningProfiles: {
                    "com.package.name1" => "provisioning name",
                    "com.package.name1" => "provisioning name",
                }
            }
        )
    end
    desc "install app to online device"
    lane :install do
        install_on_device(
            ipa: "./build/ipa_name.ipa"
        )
    end
end


参考

官网
文档

上一篇 下一篇

猜你喜欢

热点阅读