Skip to content

Instantly share code, notes, and snippets.

@pepicrft
Created October 21, 2013 23:12
Show Gist options
  • Save pepicrft/7092415 to your computer and use it in GitHub Desktop.
Save pepicrft/7092415 to your computer and use it in GitHub Desktop.
This script updates codeversion from AndroidManifest.xml file automatically. Ideal for Travis builds
# This script updates AndroidManifiest.xml file
# - Updates android:versionCode adding +1 to the version
# Reading arguments
if ARGV.length != 1
puts 'File as argument required'
exit
end
# Reading file
fileName = ARGV[0]
if File.exists?(fileName)
begin
# Read the file
manifiest = File.read(fileName)
# Get the version
version = /android\:versionCode\=\"([0-9]*)\"/.match(manifiest)
return unless version
version_line = version[0]
version_int = version[1].to_i
# Getting new version
new_version_int = version_int + 1
puts("--UPDATING AndroidManifest.xml CODE VERSION--")
puts("Current version: #{version_int}")
puts("New version: #{new_version_int}")
# Replacing
puts = manifiest.gsub(version_line, "android:versionCode=\"#{new_version_int}\"")
File.open(fileName, "w") { |file| file << puts }
puts("--VERSION UPDATED WITHIN AndroidManifest.xml--")
rescue Exception => e
puts("Something happened updating version of AndroidManifest.xml: "+e)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment