Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flavor action #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
lane :test do
value = get_version_name(
gradle_file_path:"project/build.gradle",
ext_constant_name:"versionName"
ext_constant_name:"versionName",
flavor_name: "flavor"
)
puts "VALUE = #{value}"
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class GetVersionNameAction < Action
def self.run(params)
version_name = "0"
constant_name ||= params[:ext_constant_name]
flavor_name ||= params[:ext_flavor_name]
gradle_file_path ||= params[:gradle_file_path]
if gradle_file_path != nil
UI.message("The increment_version_code plugin will use gradle file at (#{gradle_file_path})!")
version_name = getVersionName(gradle_file_path, constant_name)
version_name = getVersionName(gradle_file_path, constant_name, flavor_name)
else
app_folder_name ||= params[:app_folder_name]
UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!")
Expand All @@ -16,7 +17,7 @@ def self.run(params)
#foundVersionCode = "false"
Dir.glob("**/#{app_folder_name}/build.gradle") do |path|
UI.message(" -> Found a build.gradle file at path: (#{path})!")
version_name = getVersionName(path, constant_name)
version_name = getVersionName(path, constant_name, flavor_name)
end
end

Expand All @@ -33,16 +34,21 @@ def self.run(params)
end


def self.getVersionName(path, constant_name)
def self.getVersionName(path, constant_name, flavor_name)
version_name = "0"
is_from_selected_flavor = flavor_name == nil

if !File.file?(path)
UI.message(" -> No file exist at path: (#{path})!")
return version_name
end
begin
file = File.new(path, "r")
while (line = file.gets)
if line.include? constant_name
if flavor_name != nil && line.include? flavor_name
is_from_selected_flavor = true

if line.include? constant_name && is_from_selected_flavor
versionComponents = line.strip.split(' ')
version_name = versionComponents[versionComponents.length - 1].tr("\"","")
break
Expand Down Expand Up @@ -85,7 +91,13 @@ def self.available_options
description: "If the version name is set in an ext constant, specify the constant name (optional)",
optional: true,
type: String,
default_value: "versionName")
default_value: "versionName"),
FastlaneCore::ConfigItem.new(key: :flavor_name,
env_name: "GETVERSIONNAME_FLAVOR_NAME",
description: "If the gradle file has many flavors, specify the flavor to get versionName (optional)",
optional: true,
type: String,
default_value: nil)
]
end

Expand All @@ -100,4 +112,4 @@ def self.is_supported?(platform)
end
end
end
end
end