Android Tutorial Creating a build number for your project's compilation

It has been discussed in other places on wish lists etc that each time we compile our projects under B4A that it would nice to have a BUILD number increment by 1.

Using the CustomBuildAction described in this tutorial
http://www.b4x.com/android/forum/threads/modules-attributes.24721/

I have managed to accomplish a BUILD increment operation.

I used the Windows scripting program called wscript and a jscript file as follows

Use Notepad and save the following lines in Italics to a file somewhere convenient on your PC. In my case I used d:\myscript.js Must have js extension.

Now you will need to change ONE line your script file to match where your project is on PC.
This is highlighted below. (note the \\ in the path of the filename)

var fst, f, fileCount;
var ForReading = 1, ForWriting = 2;
var filename = "D:\\MyProject\\Files\\mybuild.txt";
fst = new ActiveXObject("Scripting.FileSystemObject");

//create file if its not found
if (! fst.FileExists(filename))
{
f = fst.OpenTextFile(filename, ForWriting, true);
f.Write("0");
f.Close();
}

f = fst.OpenTextFile(filename, ForReading);
fileCount = parseInt(f.ReadAll());

//make sure the input is a whole number
if (isNaN(fileCount))
{
fileCount = 0;
}

fileCount = fileCount + 1;

f = fst.OpenTextFile(filename, ForWriting, true);
f.Write(fileCount);
f.Close();



then in the ProjectAttributes section add the line below

#CustomBuildAction: 1, c:\windows\system32\wscript.exe, d:\myscript.js

where d:\myscript.js is the name I used for my scripting file above.

Add the file mybuild.txt to your Files directory by using the RHS Tab and Add Files.

Each time you compile the script runs, opens the file, increments the number by 1
and saves it again.

Then in your code can simply have a subroutine like below to get your current build number.

Sub get_current_build
'
Dim myline As String
txt_reader.Initialize(File.OpenInput(File.DirAssets,"mybuild.txt"))
myline = txt_reader.ReadLine
txt_reader.Close
current_build=myline
'
End Sub


Trust this helps others.
 
Last edited:

blong

Active Member
Licensed User
Longtime User
Erel

Thank you very much for the LIKE ... a privilege to have come from "the man"... :)

So could I WISH that you could build this sort of logic into B4A and have a file called "b4A_build.txt" (or whatever) residing in the Files directory so that it is easily accessible to the user. If it is a simple text file then a user can change the build number to start at whatever he wants .. in my case I set it at 100 and the let it increment. Obviously the file could be more complex and have a DATE of build as well and maybe even remember the previous build e.g.

108,10:40:07 13-SEP-2013
107, 09:45:34 11-SEP-2013

Anyway just thinking out loud :rolleyes:
 
Top