is there a way to auto-increment the version code each time you build an Android application in Eclipse?
According to http://developer.android.com/guide/publishing/v
All credit goes to ckoz, but I writed my own implementation in c#. I think it's a little faster and doesn't eat errors because If something goes wrong probably something is wrongly configured and I should know about it.
namespace AndroidVersionCodeAutoIncrement
{
using System.IO;
using System.Text.RegularExpressions;
public class Program
{
private static readonly Regex VersionCodeRegex = new Regex("android:versionCode=\"(?.*)\"", RegexOptions.Compiled);
public static void Main()
{
using (var manifestFileStream = File.Open("AndroidManifest.xml", FileMode.Open, FileAccess.ReadWrite))
using (var streamReader = new StreamReader(manifestFileStream))
{
var manifestFileText = streamReader.ReadToEnd();
var firstMatch = VersionCodeRegex.Match(manifestFileText);
if (firstMatch.Success)
{
int versionCode;
var versionCodeValue = firstMatch.Groups["version"].Value;
if (int.TryParse(versionCodeValue, out versionCode))
{
manifestFileText = VersionCodeRegex.Replace(manifestFileText, "android:versionCode=\"" + (versionCode + 1) + "\"", 1);
using (var streamWriter = new StreamWriter(manifestFileStream))
{
manifestFileStream.Seek(0, SeekOrigin.Begin);
streamWriter.Write(manifestFileText);
manifestFileStream.SetLength(manifestFileText.Length);
}
}
}
}
}
}
}