Android Tutorial Git Version ID's: Getting Tags, Commits and Hash Info

To have the Git Version Info embedded in your B4A application it is necessary to do several steps.

1. Copy a batch file (gitv.bat) to a location in the path you are using.
2. Get and install the Android Resources library.
Android Development Forum - Basic4android

3. Copy my custom "SetupGitXML.bat" file to your project folder.

Items 1,2,3 have to be done only once for each Windows machine you are working on.
Items 4,5,6 have to be done for each project.


4. Insert the #CustomBuildAction line in Project Attributes.
5. Execute the SetupGitXML.bat file.
6. Place two strings in Process_Globals, and two strings in Activity_Create

Detailed instructions are included in Instructions.txt file in the zip.
That's all it takes.

When you do a B4A build a xml file will be built in the Objects\res\values folder: gitversion.xml, it will be compiled into the R.java file at build time. The Version info is in a form similar to this: V1.10-20-ga9ecb1.
The Tag, the commit count, the hash number preceded by a "g".

You can then display or use the Git Version Info as a string resource.
B4X:
Sub Process_Globals

   'These global variables will be declared once when the application starts.

   'These variables can be accessed from all modules.

   ' THESE two lines are part of the get GIT version string.

   Dim TestString As String
   ' contains the git version information, separated by dashes "-".
               ' Tag string, number of commits since last tag, hash number preceded by "g"
   Dim AndroidResources1 As AndroidResources



End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)

   'Do not forget to load the layout file created with the visual designer. For example:

   'Activity.LoadLayout("Layout1")



' THESE two lines are part of the get GIT version string system.

       TestString = AndroidResources1.GetApplicationString("gitversion_num")

   ' The Git Version string is embedded in the res/values gitversion.xml file, which is generated new at each compile.
         ToastMessageShow (TestString,True)



End Sub
A zip file with sample source, detailed instructions, batch files is attached. The latest version 1.1 is attached from bitbucket.

!!!!!!! BE Advised that version 2.0 of this solution is now available at bitbucket.
This new version provides an incrementing build number, more complete instructions, simpler installation, better error handling and the B4A demo application can be used as a template to start any B4A project.
The tutorial above is obsolete with V2.0 and I will get around to updating it as soon as I get over the flu.

The bitbucket URL where you can download the code.
https://bitbucket.org/asllc/gitversionnumberforb4a

The two zip files below are obsolete... Sorry.
 

Attachments

  • GitVersionInfoForB4A.zip
    5.6 KB · Views: 387
  • asllc-gitversionnumberforb4a-447b30a1af20.zip
    12.5 KB · Views: 345
Last edited:
Top