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:
    Code:
    #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:
    Code:
    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:
    Code:
    Sub AppStart (Args() As String)
       
    Dim m As Map
       
    Dim path As String = "../Files/compiletime.txt"
       
    If File.Exists(path""Then
         m = 
    File.ReadMap(path"")
       
    Else
         m.Initialize
       
    End If
       m.Put(
    "autoversion", m.GetDefault("autoversion"0) + 1)
       m.Put(
    "time"DateTime.Now)
       
    File.WriteMap(path"", m)
    End Sub
    If you only want to increment the version for Release builds:
    Code:
    #If RELEASE
    #CustomBuildAction: 2, ...
    #End If
    Edit: example of code that extracts the project attributes: https://www.b4x.com/android/forum/threads/write-attribute-to-textfile.88549/#post-560535
     

    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.
Loading...
  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