class Fastlane::Actions::GetAndroidVersionAction
Public Class Methods
available_options()
click to toggle source
# 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
description()
click to toggle source
# 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
details()
click to toggle source
# 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)
click to toggle source
# File lib/fastlane/plugin/get_android_version/actions/get_android_version_action.rb, line 91 def self.is_supported?(platform) platform == :android end
output()
click to toggle source
# 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_value()
click to toggle source
# 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)
click to toggle source
# 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