快车道:如何只“增加构建号”一个目标?

14

我在Xcode项目中有两个目标:

  1. MyAwesomeApp (build 1)
  2. MyGreatApp (build 1)

执行increment_build_number动作之后,它们都变成了:

  1. MyAwesomeApp (build 2)
  2. MyGreatApp (build 2)

但我希望只将其应用于一个目标。所以当我再次执行类似以下命令的操作时: increment_builder_number(scheme: "MyAwesomeAppScheme")

它们应该变成:

  1. MyAwesomeApp (build 3)
  2. MyGreatApp (build 2) <-- 这个构建编号不应该改变

是否有实现这一点的方法呢?谢谢!

4个回答

10

这里有一个插件可以增加构建号,插件链接

在 Fastfile 中,它看起来像这样:

increment_build_number_in_plist(        
   target:"MyAwesomeApp"
)

不要忘记,目前 Faslane.swift 不支持插件 :( - Ilya Krigouzov
1
对于较新的Xcode项目,您可能需要将plist_build_setting_support: true设置添加到操作中以使其正常工作。当构建号不存储在plist中而是存储在构建设置中时,这是必需的。 - AnthoPak

7

我创建了自定义通道,利用 "xcodeproj" 可以为特定的目标名称设置版本和构建号。

# Sets the "VERSION" and "BUILD" number for a target
#
# @param args [Hash] Key value arguments. All the values are Strings. List: 
#   - target_name: The name of the target (REQUIRED)
#   - version: The version number to be used (REQUIRED)
#   - build: The build number to be used (REQUIRED)
#
desc "Sets the \"VERSION\" and \"BUILD\" number for a target"
lane :set_version_build_number do |args|
    puts("\"set_version_build_number\" lane with ARGUMENTS: #{args}")

    target_name = args[:target_name]
    version = args[:version]
    build = args[:build]

    raise(StandardError, "Invalid ARGUMENTS for: \"set_version_build_number\" LANE") unless (
        target_name != nil &&
        version != nil &&
        build != nil
    )

    puts("Variables:")
    puts("\ttarget_name: #{target_name}")
    puts("\tversion: #{version}")
    puts("\tbuild: #{build}")
    
    project_url = find_xcode_project()
    raise(StandardError, "Invalid Xcode project for: \"set_version_build_number\" LANE") unless project_url != nil
    project = Xcodeproj::Project.open(project_url)

    xc_target = project.targets.find { |target| target.name == target_name }
    raise(StandardError, "Invalid target for: \"set_version_build_number\" LANE") unless xc_target != nil

    xc_target.build_configurations.each { |build_configuration| 
        build_configuration.build_settings["MARKETING_VERSION"] = version
        build_configuration.build_settings["CURRENT_PROJECT_VERSION"] = build
    }

    project.save()
end

场景:

# Finds the location for an Xcode project within the current directory and all his parents
#
# @return [String] Full path to the Xcode project or nil if unsuccess
#
def find_xcode_project ()
    absolute_dir_path = Dir.getwd
    loop do
        entries = Dir.entries(absolute_dir_path)
        index = entries.find_index{ |entry| entry.include?(".xcodeproj") }
        if index != nil
          return "#{absolute_dir_path}/#{entries[index]}"
        end
  
        absolute_dir_path = File.dirname(absolute_dir_path)
        if absolute_dir_path == nil || absolute_dir_path == "/"
          break
        end
    end
  
    return nil
end

使用起来非常容易:

bundle exec fastlane set_version_build_number target_name:TargetApp version:2.0 build:3

当然别忘了将这个添加到Fastlane文件中:

require "xcodeproj" 

将以下内容添加到 Gemfile 中

gem "xcodeproj"

谢谢。我已经修改并更新了它,使其可以增加现有的构建号,而不必传递它。同时删除了营销版本号的设置。对于任何感兴趣的人,这里是链接: https://gist.github.com/gdavis/6b594e98ec99ea9ee51d937264d80382 - gdavis

5

请看看@NSCabezon的建议 - Morten Holmgaard

2

那么,如果要指定一个.plist文件作为参数来升级呢?类似这样:

plist_path: "./Info.plist"

3
但是,hmm,这个操作没有名为“plist_path”的参数,对吧? https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/actions/increment_build_number.rb - Sajjon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接