Android Question Compiler Time Variable

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Searched best I can but cannot find anything on our boards about this.

Is there a way I can get a Variable (long) set in my program that has the Date/Time of when the program was compiled?

eg:

B4X:
Dim CompileTime as Long = #CompilerTime


Is there a compiler directive for this?

BobVal

PS: Came across this can - will any of them work in B4A

B4X:
try{
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(),0);
ZipFile zf =newZipFile(ai.sourceDir);
ZipEntry ze = zf.getEntry("classes.dex");
long time = ze.getTime();
String s =SimpleDateFormat.getInstance().format(new java.util.Date(time));
zf.close()
;
}
catch(Exception e)
{}

B4X:
android {
defaultConfig {
buildConfigField "long","TIMESTAMP",System.currentTimeMillis()+"L"}}

Then read it at runtime.

Date buildDate =newDate(BuildConfig.TIMESTAMP);
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Solution:

1. Download writetime.jar and save it on your computer. This is a B4J program with the following code:
B4X:
Sub AppStart (Args() As String)
   File.WriteString(Args(0), "", DateTime.Now)   
End Sub

2. Add this custom build action to your B4A project:
B4X:
#CustomBuildAction: 2, C:\Program Files\Java\jdk1.8.0_51\bin\java.exe, -jar c:/temp/writetime.jar ../Files/compiletime.txt
Change the path to java and the path to writetime.

Read the compilation time:
B4X:
Log($"Compile time: $DateTime{File.ReadString(File.DirAssets, "compiletime.txt")}"$)
 

Attachments

  • writetime.jar
    81.6 KB · Views: 139
Upvote 0
Top