B4J Code Snippet b4x_cba (B4X Custom Build Action)

Ever since Erel introduced custom build actions I have used a collection of batch files to do certain things when I do a release build eg copy the jar to another folder, compile only etc.

I've finally decided to combine these into a single console application (in C#) instead of a bunch of messy batch files that use RoboCopy, WinRar, 7-zip etc.

This is a single C# console app that you copy to the B4X install folder (eg C:\Program Files\Anywhere Software\B4J) and can use in all of your B4X projects

The tool is free and open source. The source code is on GitHub - https://github.com/ope-nz/b4x_cba

If you have any suggestions for new custom build actions reply to this topic.

Supported actions;
  • compileonly - returns an error to stop b4x launching the release version of your app
  • copy - copy files or folder
  • copyjar - copys the output jar to another directory
  • buildtime - creates a file named build.txt with the build time
  • updateversion - maintains a version.txt file with increment version number
  • zip - zips a file or folder
  • moveautobackups - moves auto backup files to another directory

B4X Custom Build Action (b4x_cba)​

This is a C# console application that can be used by B4X for custom build actions.

Setup;​

  1. Copy b4x_cba.exe to your B4X install folder eg C:\Program Files\Anywhere Software\B4J
  2. Set up some custom-build actions in your project

Usage​

In your custom actions section call b4x_cba.exe with an action and other parameters

B4X:
#CustomBuildAction: 2, b4x_cba.exe, -action compileonly

Alternatively as an ide link
B4X:
'Ctrl + click to increment version: ide://run?File=b4x_cba.exe&Args=-action&Args=updateversion

See https://github.com/ope-nz/b4x_cba/blob/main/TestCustomBuildActions.b4j for all examples I use during testing.

Usage and Supported actions;​

compileonly​

b4x_cba returns a 1 exit statement to B4X which stops the app launching. This is useful for release build when you just want to compile.

NOTE: You should run this action last as it stops any further actions running.

#CustomBuildAction: 2, b4x_cba.exe, -action compileonly

copy​

b4x_cba will copy a file or folder from the source to the destination directory. "Files" can be used as a shortcut to the assets folder.

#CustomBuildAction: 2, b4x_cba.exe, -action copy --source ObfuscatorMap.txt -destination D:\Temp

or

#CustomBuildAction: 2, b4x_cba.exe, -action copy --source src -destination D:\Temp

or

#CustomBuildAction: folders ready, b4x_cba.exe, -action copy -source D:\Temp\index.html -destination Files

copyjar​

b4x_cba will copy the output jar to the specified destination directory

#CustomBuildAction: 2, b4x_cba.exe, -action copyjar -destination D:\Temp

NOTE: In the first release the second argument was named "directory" this has been changed to "destination" for consistency.

buildtime​

b4x_cba will create a file called build.txt in the Files directory of your project with the current date/time. If you omit the date/time formats they will default to yyyy-MM-dd HH:mm:ss.

NOTE: Remember to sync the files after the first run.

#CustomBuildAction: folders ready, b4x_cba.exe, -action buildtime

or

#CustomBuildAction: folders ready, b4x_cba.exe, -action buildtime -dateformat dd/MM/yyyy -timeformat HH:mm:ss

updateversion​

b4x_cba will create a file called version.txt in the Files directory of your project with an incrementing version number in format 0.0.0-9.9.9

NOTE: Remember to sync the files after the first run.

#CustomBuildAction: folders ready, b4x_cba.exe, -action updateversion

zip​

b4x_cba will zip a file or folder from the source to the destination. "Files" can be used as a shortcut to the assets folder. If the source is a file and destination filename is ommitted then the filename will be used but with a .zip extension.

#CustomBuildAction: 2, b4x_cba.exe, -action zip -source ObfuscatorMap.txt -destination D:\Temp\

or

#CustomBuildAction: 2, b4x_cba.exe, -action zip -source Files -destination D:\Temp

moveautobackups​

b4x_cba will move all auto backup files from the projects "AutoBackups" folder to another location.

NOTE: The destination is a directory but the tool will create a subfolder with the project name eg if you use D:\Temp the backups will be moved to D:\Temp\ProjectName

#CustomBuildAction: 2, b4x_cba.exe, -action moveautobackups -destination D:\Temp

or

'Ctrl + click to move autobackups: ide://run?File=b4x_cba.exe&Args=-action&Args=moveautobackups&Args=-destination&Args=D:\Temp
 
Last edited:
Top