fastlane:我怎样才能 "increment_build_number" 只有一个目标?
Fastlane: How can I "increment_build_number" of one target only?
我的 Xcode 项目中有两个目标:
- MyAwesomeApp(构建 1)
- MyGreatApp(构建 1)
increment_build_number动作后,他们都转向:
- MyAwesomeApp(构建 2)
- MyGreatApp(构建 2)
但我期望的是仅将其应用于一个目标。所以当我再次执行这样的事情时:
increment_builder_number(scheme: "MyAwesomeAppScheme")
他们转向:
- MyAwesomeApp(构建 3)
- MyGreatApp(内部版本 2)<-- 此内部版本号应保持不变
有办法实现吗?谢谢!
我可以轻松地将此选项添加到 fastlane
操作,但需要 agvtool
等效项才能完成此操作。 increment_build_number
步骤主要是 agvtool
的包装。
您可以在 Apple 文档中找到更多信息:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/agvtool.1.html
那么如何将您想要碰撞的 .plist 文件指定为参数?类似于:
plist_path: "./Info.plist"
这里有一个 plug-in 来增加内部版本号。
这是它在 Fastfile 中的样子:
increment_build_number_in_plist(
target:"MyAwesomeApp"
)
我已经创建了自定义通道,通过使用“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"
我的 Xcode 项目中有两个目标:
- MyAwesomeApp(构建 1)
- MyGreatApp(构建 1)
increment_build_number动作后,他们都转向:
- MyAwesomeApp(构建 2)
- MyGreatApp(构建 2)
但我期望的是仅将其应用于一个目标。所以当我再次执行这样的事情时:
increment_builder_number(scheme: "MyAwesomeAppScheme")
他们转向:
- MyAwesomeApp(构建 3)
- MyGreatApp(内部版本 2)<-- 此内部版本号应保持不变
有办法实现吗?谢谢!
我可以轻松地将此选项添加到 fastlane
操作,但需要 agvtool
等效项才能完成此操作。 increment_build_number
步骤主要是 agvtool
的包装。
您可以在 Apple 文档中找到更多信息:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/agvtool.1.html
那么如何将您想要碰撞的 .plist 文件指定为参数?类似于:
plist_path: "./Info.plist"
这里有一个 plug-in 来增加内部版本号。
这是它在 Fastfile 中的样子:
increment_build_number_in_plist(
target:"MyAwesomeApp"
)
我已经创建了自定义通道,通过使用“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"