Other Tool - Compile Only for B4J

Sometimes you simply want to build your application (but not run) as you ready it for source archiving, packaging, and distribution. Today there is no "compile only" option offered in the B4X tool chain.

Here's how you can implement a "compile only" feature in B4J with the assistance of a helper tool and a custom build action.

Follow this link to download the "compile only" helper tool.

http://www.macthomasengineering.com/b4x/mte_compileonly_v101.zip

Installation

1. Unzip the contents of MTE_COMPILEONLY_V101.ZIP
2. Copy COMPILEONLY.EXE to your favorite tools folder. (e.g. c:\Tools)

Usage

1. Create two build configurations: 'Compile_Only' and 'Compile_and_Run' in the project.
2. Add the conditional symbol COMPILE_ONLY to the 'Compile_Only' configuration

Compile Only Configuration

3_compileonly_build_config_zpszj3sgpul.jpg


Compile and Run Configuration

4_compileandrun_build_config_zps5qrydlt1.jpg


3. Add this custom build action to the project. ** Important ** Make sure to specify the full path (e.g. c:\tools\compileonly.exe) and a comma after compileonly.exe
B4X:
#if RELEASE
    #if COMPILE_ONLY
        #CustomBuildAction: 2, c:\Tools\compileonly.exe,
    #end if
#end if

4. Note when you choose between build configurations the "compile only" action grays.

Compile_Only build selected

1_compileonly_build_zpsogzquj9u.jpg


Compile_and_Run build selected

2_compileandrun_build_zpsqs97n9sj.jpg


Build the project

1. Select the 'Compile_Only' configuration then Project->Compile & Run
2. Build exits after the .JAR is created.

5_build_project_compileonly_zps6tlzdhyn.jpg


How it works

Compileonly.exe simply returns an errorlevel to the B4J IDE. This prompts the IDE to cancel the build. The net effect is a compile only build.
 
Last edited:

stanmiller

Active Member
Licensed User
Longtime User
Very nice!! Can it be implemented on B4A as well?

Yes, for B4A just change the build step 4 like so:
B4X:
#if RELEASE
    #if COMPILE_ONLY
        #CustomBuildAction: 4, c:\Tools\compileonly.exe,
    #end if
#end if

The build will exit after zip align.

6_b4a_compile_only_zps2kgtndpp.jpg
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
@stanmiller, thanks so much, this is brilliant. I've achieved the same thing with a small batch file that returns the same error level (ie 1).

I just call the batch file instead of your executable.

B4X:
#if RELEASE
#CustomBuildAction: 2, C:\Apps\B4J\Tools\CompileOnly\compileonly.bat,
#end if

compileonly.bat script code.

B4X:
@echo off
echo ***************************
echo Cancelling build...
echo ***************************
EXIT /B 1
 

stanmiller

Active Member
Licensed User
Longtime User
Clever. Didn't realize you could return an exit code from a .BAT.

The key, of course, is the external tool's ability to return an exit code (or errorlevel) to trigger the reaction in the IDE. One could do the same with B4J and bundle it as an .EXE. But that would be a lot of overhead to simply return a code.

Extending the idea, it would be interesting if the B4X builder would allow branching on the exit code returned to the IDE. That way you could make the build process react (not just cancel) based on the direction of an external script.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
A simpler alternative, or if you just want to do it through IDE-only means:

B4X:
'at the top of your Main module
#Region  Project Attributes
    #CommandLineArgs: compileonly

and

B4X:
Sub AppStart (Args() As String)
    If Args.Length>0 And Args(0)=="compileonly" Then
        Log("compiling and done")
        ExitApplication
    End If
'And now, the rest of your program....
 

stanmiller

Active Member
Licensed User
Longtime User
A simpler alternative, or if you just want to do it through IDE-only means:

B4X:
'at the top of your Main module
#Region  Project Attributes
    #CommandLineArgs: compileonly

and

B4X:
Sub AppStart (Args() As String)
    If Args.Length>0 And Args(0)=="compileonly" Then
        Log("compiling and done")
        ExitApplication
    End If
'And now, the rest of your program....

Very cool. This shows one can change an app launch through passing arguments through the IDE but other scenarios as well.

The advantage of the exit code trick is that the build process stops immediately after creating the .JAR (or .APK if applying the technique to B4A). With a runtime test you still have the expense of launching the Java VM only to exit immediately.

.
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
Or even simpler, just add this to the project;

B4X:
    #if RELEASE
        #CustomBuildAction: 2, c:\windows\system32\cmd.exe,/C echo Cancelled build... && Exit /B 1
    #end if

This will return an error to the build action and stop it launching the app.
 

virpalacios

Active Member
Licensed User
Longtime User
Excellent Job, it is great while we wait for Compile Only Option in tool bar,
Best Regards
 
Top