Class: Fastlane::Actions::GetAndroidVersionAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



60
61
62
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 60

def self.authors
  ["MaximusMcCann"]
end

.available_optionsObject



73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 73

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :apk,
                            env_name: "GET_ANDROID_VERSION_APK",
                         description: "The apk to get the versionName and versionCode from",
                            optional: false,
                                type: String)
  ]
end

.descriptionObject



56
57
58
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 56

def self.description
  "Gets the android versionName, versionCode and parsed appName (label) from AndroidManifest.xml file in provided apk"
end

.detailsObject



68
69
70
71
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 68

def self.details
  # Optional:
  "Gets the android versionName, versionCode and parsed appName (label) from AndroidManifest.xml file in provided apk"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 91

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

.outputObject



83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 83

def self.output
  [
    ['GET_ANDROID_VERSION_NAME', 'The versionName extracted from the apk\'s manifest file.'],
    ['GET_ANDROID_VERSION_CODE', 'The versionCode extracted from the apk\'s manifest file. Hex values are converted to ints.'],
    ['GET_ANDROID_VERSION_APP_NAME', 'The appNmae extracted from the apk\'s manifest file.']
  ]
end

.return_valueObject



64
65
66
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 64

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

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb', line 9

def self.run(params)
  require 'apktools/apkxml'

  apk_file = params[:apk]

  # NOTE!! ALL CREDIT DUE HERE: https://github.com/devunwired/apktools/blob/master/bin/get_app_version.rb

  # Load the XML data
  parser = ApkXml.new(apk_file)
  parser.parse_xml("AndroidManifest.xml", false, true)

  elements = parser.xml_elements

  versionCode = nil
  versionName = nil
  appName = nil

  elements.each do |element|
    if element.name == "manifest"
      element.attributes.each do |attr|
        if attr.name == "versionCode"
          versionCode = attr.value
        elsif attr.name == "versionName"
          versionName = attr.value
        end
      end
    elsif element.name == "application"
      element.attributes.each do |attr|
        if attr.name == "label"
          appName = attr.value
        end
      end
    end
  end

  if versionCode =~ /^0x[0-9A-Fa-f]+$/ #if is hex
    versionCode = versionCode.to_i(16)
  end

  Actions.lane_context[SharedValues::GET_ANDROID_VERSION_NAME] = "#{versionName}"
  Actions.lane_context[SharedValues::GET_ANDROID_VERSION_CODE] = "#{versionCode}"
  Actions.lane_context[SharedValues::GET_ANDROID_VERSION_APP_NAME] = "#{appName}"

  UI.message("Data pulled from: #{apk_file}")
  UI.message("extracted versionName: #{versionName} & versionCode: #{versionCode} & appName: #{appName}")
end