B4J Tutorial Integrated B4JPackager11 - The simple way to distribute standalone UI apps

Status
Not open for further replies.
B4JPackager11 is a utility written in B4J that uses the underlying Java tools to create a standalone package that doesn't depend on any other software being installed.
It works with OpenJDK 11 and OpenJDK 14.
Starting from B4J v8.30 it is integrated in the IDE and available under Project - Build Standalone Package.
External tool: https://www.b4x.com/android/forum/t...lest-way-to-distribute-ui-apps.99835/#content

Example:

Shw8yVDjRi.gif


The output of this tool looks like this:

explorer_fa8Z3lAQP3.png


You need to distribute the executable together with the 4 folders.
The run_debug.bat batch file is useful to test the program and see the logs.

An Inno Script template is created in the parent folder. You can use it together with Inno Script to build a single file installer.

The integrated packager creates a Windows package. You can however use the external tool with the generated json file (in the project folder) to create Linux and Mac packages.

The packager supports all kinds of settings. You can set them with the new #PackagerProperty attribute.

For example to set the icon file, assuming that the ico file is in the Files tab and is named turtle.ico:
B4X:
#PackagerProperty: IconFile = ..\Files\turtle.ico
Also set the executable name:
B4X:
#PackagerProperty: IconFile = ..\Files\turtle.ico
#PackagerProperty: ExeName = Turtle
Note that this will set the executable icon. Set the form icon with the designer. The form icon should be a regular image file (png, jpg, ...).

Tips and special cases

  1. If using jPOI library then you must reference XLUtils.
  2. If using WebView or HtmlEditor add:
    B4X:
    #PackagerProperty: IncludedModules = javafx.web
  3. If using jGoogleMaps add:
    B4X:
    #PackagerProperty: IncludedModules = javafx.web
    #PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.javascript.event;
    There is an issue with Java 14 and Google Maps. Use Java 11 for now if using jGoogleMaps.
  4. You can use #CustomBuildAction with the new After Packager step to copy files after the package is built. The default target folder should be: temp\build\bin\
  5. If using jSerial put the attached jssc.dll file in the project folder and add:
    B4X:
    #CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ jssc.dll
    Note that it is a Windows 64 bit dll.
    MacSigner instructions: https://www.b4x.com/android/forum/threads/mac-and-jssc.135823/post-859095
  6. Each PackagerProperty key should appear at most once. So for example if using both WebView and jPOI add: #PackagerProperty: IncludedModules = jdk.charsets, javafx.web
    Starting from B4J 9.00, the same property can appear multiple times and the values will be appended.
  7. If you get an error that looks like: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure, add:
    B4X:
    #PackagerProperty: IncludedModules = jdk.crypto.ec
  8. If using jWebSocketClient then you need to add:
    B4X:
    #PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.websocket.common.RemoteEndpointFactory;
  9. If you want to copy the generated build to a different folder (C:\Users\H\Downloads\test for example):
    B4X:
    #CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, /MIR temp\build\ C:\Users\H\Downloads\test
    Warning : the destination folder will be deleted recursively.
  10. A json file named packager.json is created in the Objects folder. You can use it to run the external packager tool, for example to build Mac or Linux packages.
  11. Steps to automatically build the setup file with Inno Script:
    • Move the generated InstallerScript-template.iss file to the project folder and rename it to InstallerScript.iss.
    • Edit the script, change the app name, publisher and other fields as needed. You also need to update two paths as explained in post #3.
    • Put the icon file in the project folder.
    • Add this attributes:
      B4X:
      #PackagerProperty: IconFile = ..\turtle.ico
      #CustomBuildAction: After Packager, C:\Program Files (x86)\Inno Setup 6\Compil32.exe, /cc ../InstallerScript.iss
    • Output after choosing Project - Build standalone package:

      explorer_ZR0Ey83790.png

    • Note that the AppId field shouldn't be changed after you distribute your app.
  12. By default, not all of the localization data is added to the package. This can cause for example, the dates to appear in English even when the default locale is non-English. You can add the missing data with:
    B4X:
    #PackagerProperty: IncludedModules = jdk.localedata
    It will add about 9mb to the built package.
    (Don't miss tip #6 if you need to add multiple modules.)
 

Attachments

  • jssc.zip
    38 KB · Views: 1,000
Last edited:

bdunkleysmith

Active Member
Licensed User
Longtime User
This is a great addition @Erel!

You'd know I particularly like the ability to automatically add jssc.dll when using jSerial.

Is there a default InstallerScript.iss somewhere that is used when InstallerScript-Template.iss is created in the temp folder so just like when using B4JPackager11 one can set parameters to suit one's own particular circumstances rather than having to edit InstallerScript-Template.iss each time it is created?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't edit the template each time. Make a copy and store it in the project main folder.

You need to change two paths:
B4X:
SetupIconFile=Objects\temp\icon.ico

And:
B4X:
[Files]
Source: Objects\temp\build\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
 

R D Boozer

Member
Licensed User
What effect (if any) will this change have on the process used to port an app via the B4JPackager11 to Linux and Mac OS? I have ported an app to Ubuntu with no problem using the unintegrated B4JPackager11 and am currently getting ready to try porting the same app to Mac OS.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
What effect (if any) will this change have on the process used to port an app via the B4JPackager11 to Linux and Mac OS?
You can use the generated json file if you like. Other than that there is no difference. The integrated BP11 is exactly the same as the non-integrated one.
 

Mark Turney

Active Member
Licensed User
Longtime User
The process worked perfectly. I was able to easily create a standalone package for my app Visual Segment Designer from within B4J v.8.30. Then, it was also easy to turn that package into a single-file installer using Inno Script. You can access the exe here: https://www.icloud.com/iclouddrive/0O7JAzGnyu4_jLge38wD6AKcQ#Misc_Files

FYI - I created a custom icon using IcoFx.
 

Dadaista

Active Member
Licensed User
Longtime User
Hi
I am getting this error with the icon. Invalid Data
The icon.ico is in the folder and I can open it with Gimp. :rolleyes:
B4X:
c:\Users\dbsai\Documents\B4J Proyectos\Caja\Objects\temp\build\Caja Venta.exe: error CS1567: 
Error al generar el recurso Win32: Error al leer el icono 'c:\Users\dbsai\Documents\B4J Proyectos\Caja\Objects\temp\icon.ico' 
- Datos no v?lidos.

in code:
B4X:
#PackagerProperty: IconFile = ..\iconcaja.png
#CustomBuildAction: After Packager, C:\Program Files (x86)\Inno Setup 6\Compil32.exe, /cc ../Caja Venta.iss

Instructios from post#3 followed

Caja Venta.iss is my script that I normally use to generate the setup with b4jpackager11 (all is 0k from b4jpackager11) File.iss copied to project folder as the app icon too with .png extension

How Can I solve it?

Thanks!!
 

Dadaista

Active Member
Licensed User
Longtime User
Hi
Thank you for response
what?.... obviously I am ussing a .png file and it is (obviously) an ico file.?. 48 x 48 (32 bits)
That works fine in b4jpackager11 and now is not working. I only wanna know what is the problem to solve it. That is all.
I will try to change file format of the icon from .png to .ico with gimp.
 

Dadaista

Active Member
Licensed User
Longtime User
Solved!
The file extension must be ".ico"... I did the change with GIMP. I do not know if only changing (rename) the extension of the file, works
 
Last edited:

Dadaista

Active Member
Licensed User
Longtime User
Now the problem is that the icon is not showed in the left top of the program window :mad::mad::mad::mad:
 

Revisable5987

Member
Licensed User
add the icon in designer, or code
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    MainForm.Icon = <----
End Sub

Annotation 2020-05-26 002129.png
 
Last edited:

Dadaista

Active Member
Licensed User
Longtime User
Hi
It is added
B4X:
MainForm.Icon = fx.LoadImage(File.DirAssets, "iconcaja.ico")

?
 
Status
Not open for further replies.
Top