I have done it. And here is how I did it for the next guy (using Eclipse):
1) Create an executable file of the external console that is going to write the code for the new version in AndroidManifest.xml: (mine is in C #)
using System.IO; using System.Text.RegularExpressions; namespace AndroidAutoIncrementVersionCode { class Program { static void Main(string[] args) { try { string FILE = @"AndroidManifest.xml"; string text = File.ReadAllText(FILE); Regex regex = new Regex(@"(?<A>android:versionCode="")(?<VER>\d+)(?<B>"")", RegexOptions.IgnoreCase); Match match = regex.Match(text); int verCode = int.Parse(match.Groups["VER"].Value) + 1; string newText = regex.Replace(text, "${A}" + verCode + "${B}", 1); File.WriteAllText(FILE, newText); } catch { } } } }
aside: any c-sharp compiler can create this application, you do not need Visual Studio or even Windows
- If you don’t have it yet, install .NET runtime ( Mono will work, link ) ( link to MS.NET framework 2.0, 2.0 - the smallest download, any version> = 2.0 is fine )
- copy this code to the
*.cs file (I called mine: AndroidAutoIncrementVersionCode.cs ) - open a command prompt and go to where you created the
*.cs file - create a file using this command (on Windows, similar to Mono, but change the compiler path):
c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc AndroidAutoIncrementVersionCode.cs (see c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc AndroidAutoIncrementVersionCode.cs NET or Mono for more details ) congrats, you just created a C # application without any tools, it should have generated AndroidAutoIncrementVersionCode.exe in the same directory automatically
** mileage may vary, paths may be different, no purchase required, void where prohibited, I added this because C # is awesome and people mistakenly believe that it has an MS lock, you could just transfer it to another language (but I'm not going to do it for you;). By the way, any version of any .NET compiler will work, I adapted the code for the least common denominator ... *
end>
2) Run the executable file during the build process: a) Go to the project properties

b) In the properties, go to "Builders" → "Create ..."

c) Select "Program"

d) On the "Home" tab, select the location of the program (I also set the working directory to a safe state) and give it a name if you want.

e) On the Refresh tab, select the option “Refresh resources after completion” and “Selected resource” - this will update the manifest after it is written.

f) On the "Assembly Options" tab, you can disable "Allocate Console" because you do not have input and output, and then select only "During manual assemblies" and "During automatic assembly" clear the "After cleaning" checkbox if This is verified. Then select "Specify a working set of relevant resources" and click the "Specify resources ..." button. In the "Change Working Set" dialog box, find the file "AndroidManifest.xml" in the dialog box and check it, then click "Finish"


f) Now click "OK" inside the "Edit configuration dialog" and in the properties of your application, select the newly created builder and click "Up" until it appears at the top of the list, so auto increment starts first and does not trigger random states synchronization or adjustment. Once the new creator that you created is at the top of the list, click OK and you're done.


ckozl Nov 16 '11 at 18:34 2011-11-16 18:34
source share