Class: Fastlane::Actions::AndroidChangeAppNameAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



36
37
38
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 36

def self.authors
  ["MaximusMcCann"]
end

.available_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 48

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

.descriptionObject



32
33
34
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 32

def self.description
  "Changes the manifest's label attribute (appName).  Stores the original name for revertinng."
end

.detailsObject



44
45
46
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 44

def self.details
  "Changes the apk manifest file's label attribute (appName).  Stores the original label value for reverting later."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 70

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

.outputObject



64
65
66
67
68
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 64

def self.output
  [
    ['ANDROID_CHANGE_APP_NAME_ORIGINAL_NAME', 'The original app name.']
  ]
end

.return_valueObject



40
41
42
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 40

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

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/android_change_app_name/actions/android_change_app_name_action.rb', line 7

def self.run(params)
  require 'nokogiri'

  newName = params[:newName]
  manifest = params[:manifest]

  doc = File.open(manifest) { |f|
    @doc = Nokogiri::XML(f)

    originalName = nil

    @doc.css("application").each do |response_node|
      originalName = response_node["android:label"]
      response_node["android:label"] = newName

      UI.message("Updating app name to: #{newName}")
    end

    Actions.lane_context[SharedValues::ANDROID_CHANGE_APP_NAME_ORIGINAL_NAME] = originalName

    File.write(manifest, @doc.to_xml)
  }

end