Android Tutorial Compilation time and auto-increment build version

Discussion in 'Tutorials & Examples' started by Erel, Mar 2, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This tutorial demonstrates how the custom build action feature can be used to add a file during compilation with the compilation time and an automatic version number that is incremented with every compilation.

    Using it is simple:

    1. Download the attached jar file and save it.
    2. Add this line to your project:
    #CustomBuildAction: 2, C:\Program Files\Java\jdk1.8.0_51\bin\java.exe, -jar c:\temp\compiletime.jar
    Change the path to java and the path to the downloaded jar.

    During compilation a file named compiletime.txt will be created in the Files folder.
    You can read its data with:
    Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
    Dim compiledata As Map = File.ReadMap(File.DirAssets, "compiletime.txt")
    Log($"autoversion: ${compiledata.Get("autoversion")}"$)
    Log($"compilation time: $DateTime{compiledata.Get("time")}"$)
    End If
    End Sub
    Run your app once and then go to the Files tab and click on Sync button (this will remove the file warning).

    The small utility code (B4J) is:
    Sub AppStart (Args() As String)
    Dim m As Map
    Dim path As String = "../Files/compiletime.txt"
    If File.Exists(path""Then
         m = 
    End If
    "autoversion", m.GetDefault("autoversion"0) + 1)
    File.WriteMap(path"", m)
    End Sub
    If you only want to increment the version for Release builds:
    #CustomBuildAction: 2, ...
    #End If
    Edit: example of code that extracts the project attributes:

    Attached Files:

    Last edited: Jan 21, 2018
  2. RauchG

    RauchG Active Member Licensed User

    How can the autoversion to 0.0?
  3. Erel

    Erel Administrator Staff Member Licensed User

    Delete compiletime.txt from the files folder.
    RauchG likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice