Class: Fastlane::Actions::RenameAndroidAppNameAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



46
47
48
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 46

def self.authors
  ["Sourcetoad"]
end

.available_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 58

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :new_name,
                                 env_name: "FL_RENAME_ANDROID_PACKAGE_NEW_APP_NAME",
                                 description: "The new name for the app",
                                 optional: true,
                                 type: String,
                                 default_value: ""),
    FastlaneCore::ConfigItem.new(key: :manifest,
                                 env_name: "FL_RENAME_ANDROID_PACKAGE_ANDROID_MANIFEST_PATH",
                                 description: "Optional custom location for AndroidManifest.xml",
                                 optional: true,
                                 type: String,
                                 default_value: "app/src/main/AndroidManifest.xml")
  ]
end

.descriptionObject



42
43
44
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 42

def self.description
  "Changes the manifest's label attribute (appName)."
end

.detailsObject



54
55
56
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 54

def self.details
  "Changes the apk manifest file's label attribute (appName)."
end

.find_elements(node, name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 29

def self.find_elements(node, name)
  results = []
  return results unless node.respond_to?(:nodes)

  node.nodes.each do |child|
    next unless child.kind_of?(Ox::Element)

    results << child if child.name == name
    results.concat(find_elements(child, name))
  end
  results
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 79

def self.is_supported?(platform)
  platform == :android
end

.outputObject



75
76
77
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 75

def self.output
  []
end

.return_valueObject



50
51
52
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 50

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fastlane/plugin/rename_android/actions/rename_android_app_name_action.rb', line 12

def self.run(params)
  require 'ox'

  new_name = params[:new_name]
  manifest = params[:manifest]

  xml = File.read(manifest)
  doc = Ox.parse(xml)

  find_elements(doc, 'application').each do |app_node|
    app_node['android:label'] = new_name
    FastlaneCore::UI.message("Updating app name to: #{new_name}")
  end

  File.write(manifest, Ox.dump(doc, indent: 2))
end