B4J Tutorial [B4X] Using/running B4A and/or B4J on 64 bit Linux Mint 20.2 Cinnamon with 64 bit Wine

*** Contents ***
Intro
Acknowledgements
Disclaimer
Environment
Conventions used in this post
Making it work
Compiling and running your programs
A semi-automated way to get your B4J UI programs ready
Android SDK Manager
Useful tips

*** Intro ***
Ever since the arrival of Windows 10 and all its 'telemetry' (<cough>spyware</cough>) I've been considering leaving Windows behind and moving to Linux. Being a more or less complete newbie to Linux, it had to wait until I had time to start doing this in a proper way: I'm a hands-on guy, I don't want to study for months and only then start using the acquired (and meanwhile probably forgotten) knowledge. In other words, dive in at the deep end and start swimming.

In this post I've documented the steps I took for both B4A and B4J as it seemed better to keep all of it in one place.

Last but not least, I didn't want the overhead of a Windows virtual machine with e.g. VirtualBox.

*** Acknowledgements ***
- Many thanks to @Mihai Rainer Jr. whose thread was absolutely crucial for me as a starting point and on which this one is 99% based: https://www.b4x.com/android/forum/t...under-linux-with-wine-fully-functional.98431/.
- And also many thanks to @EnriqueGonzalez for providing adb version 1.0.40 for Windows and Linux (more about this below).

*** Disclaimer ***
As I mentioned, Linux is mostly a new planet for me. If you would ask questions in this here thread and I happen to know the answer, I'll gladly provide it. However, I won't be searching the web to get those answers - you can do that as well and I want to spend my time digging deep into the Linuxverse :) Many steps have been copied from @Mihai Rainer Jr.'s thread and at the moment I might not even know/understand why they're needed; all I can say is: it works here.

*** Environment ***
- B4J v9.10 through v9.50 (the former is 32-bit, the latter is 64-bit)
- B4A v11.0 through v11.50
- Linux Mint 20.2 Cinnamon (64 bit); installed from a Live USB stick, all default values used
- Wine 5.0 (Ubuntu 5.0-3ubuntu1) (64 bit)
- Laptop: 8 Gb, AMD Ryzen 3 2200U with Radeon Vega Mobile Gfx (in section 'Useful tips' there is a note about the Ryzen processors)
- Desktop: 16 Gb, AMD FX-6300 Six-Core Processor 3.50 GHz

*** Conventions used in this post ***
- Steps that are intended for one particular platform only are prefixed with [B4A] c.q. [B4J]; all others are applicable for both products.
- Wherever 'YOUR_USER_NAME' is used in paths, replace it with your user name (duh, really).

*** Making it work ***
1. Open a terminal window and enter the following commands:
B4X:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install wine64 winetricks
cd
mkdir virtualwinedrives
mkdir virtualwinedrives/b4x64
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" WINEARCH=win64 wine wineboot

Warning: @fgh3966 experienced a bug with Wine 8.0.0 and had to revert to version 7.0.1 (https://www.b4x.com/android/forum/threads/bug-wine-8-0-0-maj.145801/)

2. Download the 'dotnet 4.5.2 redistributable (offline version)' (at the time of writing it could be obtained at https://www.microsoft.com/en-us/download/details.aspx?id=42642 ; search the web if the location would have changed).

3.
B4X:
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" winetricks
- Select 'Select the default wine prefix' and click 'OK'
- Select 'Run winecfg' and click 'OK'
- In tab 'Applications', make sure 'Windows Version' (at the bottom) says 'Windows 7'; if you had to change it, click 'Apply' - thanks to @rwblinn for this tip
- In tab 'Graphics', select a 'Screen resolution' of 100 or more, then click 'OK'
- Select 'Install a Windows DLL or component' and click 'OK'
- Check the boxes for 'dotnet452' and 'vcrun2010', then click 'OK'; click 'OK' (or 'Continue' where applicable) in all the warning messages that pop up, and wait for the installations to complete
- A message will pop up stating you must restart your computer; click 'Restart Now' as this will only terminate Wine

If you would get an error message about the package being broken, winetricks will terminate. In that case, do this:
B4X:
winetricks --force dotnet452
winetricks --force vcrun2010

4.
B4X:
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" winetricks
- Select 'Select the default wine prefix' and click 'OK'
- Select 'Run winecfg' and click 'OK'; in tab 'Applications', make sure 'Windows Version' (at the bottom) says 'Windows 7' (because the Wine built-in dotnet installer switches this to 'Windows 2003'), click 'OK'
- Select 'Run uninstaller', click 'OK', then click the 'Install' button in that window; navigate to your 'Downloads' directory (or wherever you saved the downloaded 'dotnet 4.5.2 redistributable (offline version)'), change 'Files of type' at the bottom to 'All files (*.*)', select the downloadeded installer, click 'Open', select 'Repair .NET Framework 4.5.2 to its original state', click 'Next', click 'OK' (or 'Continue' where applicable) in all the warning messages that pop up, and wait for the installation to complete
- Close all windows by clicking 'OK' (and 'Cancel' in the very last window)

5. Restart the Wine Prefix (important: under your user, not root!):
B4X:
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" wineboot --restart

6. Download B4A and/or B4J and their required components (Android SDK, JDK, ...) from https://www.b4x.com.

7.
B4X:
mkdir /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java

8. Extract (e.g. via 'Files', the file manager) the jdk you downloaded from the B4X site to /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java so that directory /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java/jdk-11.0.1 exists.

9.
B4X:
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" winetricks
- Select 'Select the default wine prefix' and click 'OK'
- Select 'Run uninstaller', click 'OK', and click the 'Install' button
- Change 'Files of type' at the bottom to 'All files (*.*)', select B4A.exe, click 'Open', and install B4A; during installation, check the box to create a desktop icon
- Change 'Files of type' at the bottom to 'All files (*.*)', select B4J.exe, click 'Open', and install B4J; during installation, check the box to create a desktop icon
- Click 'OK' to close the 'Add/Remove Programs' window
- Select 'Change settings' and click 'OK'; check the checkboxes in front of these ones and then click 'OK':
ddr=gdi (this one may be absent from the list, which doesn't seem to be a problem)
glsl=enabled
orm=fbo
videomemorysize=512
- Click 'OK'; also dismiss the warning messages that pop up
- Click 'OK', and then in the main Winetricks window click 'Cancel' to close Winetricks

10. Now could be a good time to copy the relevant folders with your B4X projects, additional libraries, and shared modules from your Windows environment. If you copy them to your '/home/YOUR_USER_NAME/Documents' directory, you'll find them in 'My Documents' under Wine, e.g. when opening a project in B4X.

11. [B4A]
B4X:
mkdir /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android

12. [B4A] Extract (e.g. via 'Files', the file manager) the Android SDK tools you downloaded from the B4X site (at the time of writing, this was 'commandlinetools-win-6609375_latest.zip') to /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android so that directory /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android/cmdline-tools exists.

13. [B4A] Extract (e.g. via 'Files', the file manager) the Android Resources you downloaded from the B4X site (at the time of writing, this was 'resources_06_21.zip') to /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android so that several new directories now exist in that directory.

14. Starting B4A and B4J can be done by double-clicking the desktop icons. An alternative way to run e.g. B4A is (B4J is of course similar):
B4X:
cd '/home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/Program Files (x86)/Anywhere Software/Basic4android'
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" wine ./B4A.exe

NOTE: the default installation folder for the 64-bit versions of B4A and B4J is 'Program Files' while the 32-bit versions use 'Program Files (x86)'. Modify the aforementioned path as appropriate, if applicable.

15. Run B4A and B4J (by double-clicking the desktop icon) and configure the paths via Tools->'Configure Paths' in both; in B4A, the SDK Manager will not work but - as mentioned on the B4X site - you don't need it. If for some reason you would want/need it, see section 'Android SDK Manager' below. If you used the paths from this post, you can copy and paste the following information for the first two:
- javac.exe: C:\java\jdk-11.0.1\bin\javac.exe
- android.jar (for SDK level 30): C:\android\platforms\android-30\android.jar
- Additional Libraries: that's a custom one from you
- Shared Modules: that's a custom one from you

16. [B4A] In B4A, don't forget to set/load your Private Sign Key (from the 'Tools' menu). Failing to do so, you won't be able to install existing apps on your devices as for Android they will appear to come from a different creator.

17. [B4A] NOTE: when connecting B4A Bridge, a message pops up stating 'Ping failed (IP = xxx.xxx.xxx.xxx): The IP address is most probably incorrect. Do you want to use it?'; click 'Yes', it won't stop you from connecting to your Android device.

18. NOTE: Designer works fine in both B4A and B4J, but the WYSIWYG Designer window is completely black (apart from the title bar).

19. [B4A] adb must be version 1.0.40 for both Windows (for Wine) and Linux (platform tools 28.0.2); you can check this with
B4X:
adb version
You can download both versions in one zip file from https://www.dropbox.com/sh/a45a6ym8l1ue5fk/AAB-7ocL5O4kSvT7cChZB5LEa?dl=0 (thank you @EnriqueGonzalez). In a next step, I will explain what to do with the downloaded file.

20. [B4J]
B4X:
mkdir /home/YOUR_USER_NAME/java
mkdir /home/YOUR_USER_NAME/B4X
mkdir /home/YOUR_USER_NAME/B4X/platform-tools

21. [B4J] Download B4JPackager11 from https://www.b4x.com/android/forum/t...the-simplest-way-to-distribute-ui-apps.99835/, compile it, and copy file 'B4JPackager11.jar' from the project's Objects folder to Linux directory /home/YOUR_USER_NAME/B4X.

22. [B4J]
Download and unzip https://b4xfiles-4c17.kxcdn.com/b4j/linux_jdk-11.0.1.zip as per https://www.b4x.com/android/forum/threads/b4jpackager11-the-simplest-way-to-distribute-ui-apps.99835 and extract (e.g. via 'Files', the file manager) its contents to /home/YOUR_USER_NAME/java so that directory 'jdk-11.0.1' now exists in that directory.

23. [B4A]
B4X:
mv /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android/platform-tools /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android/platform-tools-r30
mkdir /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android/platform-tools
mkdir /home/YOUR_USER_NAME/B4X
mkdir /home/YOUR_USER_NAME/B4X/platform-tools

24. [B4A] Extract (e.g. via 'Files', the file manager) the Windows adb 1.0.40 (platform-tools_r28.0.2-windows.zip) you downloaded from the Dropbox link to /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/android/platform-tools so that several new directories now exist in that directory.

25. [B4A] Extract (e.g. via 'Files', the file manager) the Linux adb 1.0.40 (platform-tools_r28.0.2-linux.zip) you downloaded from the Dropbox link to /home/YOUR_USER_NAME/B4X/platform-tools so that several new directories now exist in that directory.

26. [B4A]
- Launch the text editor (click the Linux Mint menu button in the bottom left corner, type 'text' in the search box, click 'Text Editor')
- Right-click in the large pane on the right and click 'Show Hidden Files' if it's not already checked
- Navigate to 'Home'
- Double-click file '.bashrc' and add the following lines:
B4X:
# Start the Linux version of adb by just typing 'adb'
alias adb='/home/YOUR_USER_NAME/B4X/platform-tools/adb'
# Have the WINEPREFIX environment variable available at all times
export WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64"
- Save the file

27. [B4J]
- Launch the text editor (click the Linux Mint menu button in the bottom left corner, type 'text' in the search box, click 'Text Editor')
- Right-click in the large pane on the right and click 'Show Hidden Files' if it's not already checked
- Navigate to 'Home'
- Double-click file '.bashrc' and add the following lines:
B4X:
# Start the Linux B4Jpackager by just typing 'b4jpkg'
# Note: this assumes that 'packager.json' is present in the current working directory and was properly edited
alias b4jpkg='/home/YOUR_USER_NAME/java/jdk-11.0.1/bin/java -jar /home/YOUR_USER_NAME/B4X/B4JPackager11.jar packager.json'
- Save the file

28. - Launch the text editor (click the Linux Mint menu button in the bottom left corner, type 'text' in the search box, click 'Text Editor')
- Right-click in the large pane on the right and click 'Show Hidden Files' if it's not already checked
- Navigate to 'Home'
- Double-click file '.bashrc' and add the following lines:
B4X:
# Ensure CustomBuildActions will recognise '%windir%'
export windir="c:\windows"
- Save the file

29. Log out, and log in again to make sure the updated .bashrc information will be available to all processes. (Possibly a
B4X:
source .bashrc
command will take care of this too, but I'm not sure - Linux newbie here as I mentioned)

30. [B4A] Check if adb is working (USB debugging must have been enabled in the Developer Options of the Android device):
- Connect your Android phone to the computer via USB
- In a Terminal window, type
B4X:
adb devices
- adb should then report something like:
B4X:
List of devices attached
041c68157d25 device
- In case an issue comes up, use commands 'adb kill-server' and 'adb start-server', and then retry 'adb devices'

31. [B4J] If you intend to use InnoSetup to produce single-file installers for your B4J programs, download it from https://jrsoftware.org/isinfo.php and install it with
B4X:
wine innosetup...
(use the appropriate filename).

That's it. You should now be able to use B4A and B4J on Linux! Make sure you read the 'Useful tips' section below; it may save you a lot of time if strange things (don't) seem to be happening.

*** Compiling and running your programs ***
B4A
:
Business as usual, run the IDE, connect to your device with B4A Bridge (ignore the 'can't ping' warning) and do your thing.

B4J - non-UI programs:
Run the IDE, compile your program, use the jar file; nothing additional needs to be done.

B4J - UI programs - running on a system that has Java installed (assuming you installed Java under /home/YOUR_USER_NAME/java/jdk-11.0.1):
B4X:
/home/YOUR_USER_NAME/java/jdk-11.0.1/bin/java --module-path /home/YOUR_USER_NAME/java/jdk-11.0.1/javafx/lib --add-modules ALL-MODULE-PATH -jar PATH_TO_YOUR_JAR

B4J - UI programs packaged to run on a system that doesn't have Java installed (some steps can be done differently - this is how I do it; also see 'A semi-automated way to get your B4J UI programs ready' below for an easier way to do this):
1. From the IDE, use option Project->'Build Standalone Package'; now, the Windows version is ready and a 'packager.json' file has been created

2.
B4X:
cd
mkdir B4Jprograms
cd B4Jprograms
mkdir YOUR_PROJECT_NAME
cd YOUR_PROJECT_NAME

3. If, as suggested before, you put your B4X projects under your Documents directory, you'll find the project folder and its subfolders there

4. From the project's Objects folder, copy the jar file and 'packager.json' to /home/YOUR_USER_NAME/B4Jprograms/YOUR_PROJECT_NAME

5. Edit packager.json as appropriate; you may need to adjust values such as the path to the icon file

6.
B4X:
b4jpkg

7. A new directory 'temp' is created which contains directory 'build' which contains file 'run.command'

8. To start the program, do this:
B4X:
cd temp/build
./run.command

*** A semi-automated way to get your B4J UI programs ready ***
This is useful to prepare programs to run on a system that doesn't have Java installed. Obviously, all this happens in the Linux environment. Two steps are involved:
A. CopyFilesForLinuxify (runs under Wine as a CustomBuildAction): prepares the necessary files for Linuxify
B. Linuxify (runs natively under Linux): packages your program and produces an executable script to launch it

A. CopyFilesForLinuxify
1. Compile the attached 'CopyFilesForLinuxify' project and copy its jar (from the project's Objects folder) to your B4J 'Additional libraries' directory.

2. You'll need a top-level directory in which subdirectories will be created that will hold your B4J projects' executables. In this section, I will assume that this directory is '/home/YOUR_USER_NAME/Documents/B4Jprograms'. CopyFilesForLinuxify will create that directory if it doesn't already exist.

3. Important: CopyFilesForLinuxify determines whether or not it is running on Linux under Wine. If not, it doesn't produce the target files (it does, however, delete the temp directory if so instructed). Environment variable 'WINEPREFIX' must be set to a non-empty string value in the Linux environment; if you followed the instructions in section 'Making it work', this will have been done.

4. Now, all you have to do is add this CustomBuildAction to your B4J UI programs (and edit it for each program):
B4X:
#CustomBuildAction: after packager, %ADDITIONAL%\CopyFilesForLinuxify.jar, "C:\Users\YOUR_USER_NAME\My Documents\B4Jprograms" MyProgram Y ..\icon.icon
The arguments it accepts are as follows:
- the full path of the directory mentioned in (2)
- the project's jar file name without path or extension
- Y to delete the temp folder, N to leave it alone (this is the folder that is created by B4Jpackager11)
- optionally, the path to the icon file you want to use for your project; most likely the same one that you specified for '#PackagerProperty: IconFile' if you did so

5. Finally, use Projects -> Build Standalone Package to compile your project, build the package, and prepare the necessary files for Linuxify. A new directory with the same name as your project will be created under '/home/YOUR_USER_NAME/Documents/B4Jprograms', and the project's jar and packager.json files that were created by B4Jpackager11 will have been copied to it.

B. Linuxify
I am assuming that you have used the paths (for java and B4JPackager11) that were suggested in section 'Making it work'.

Once, to prepare Linuxify for use on the target Linux system:
- Build the attached project with B4J on Windows (or on Linux under Wine): Project -> Build Standalone Package
- Folder Objects\temp can be deleted
- In folder Objects, edit packager.json and remove path information, just keep the filenames
-
B4X:
cd
mkdir Linuxify
- From folder Objects, copy the jar and packager.json files to Linux directory /home/YOUR_USER_NAME/Linuxify
-
B4X:
cd /home/YOUR_USER_NAME/Linuxify
/home/YOUR_USER_NAME/java/jdk-11.0.1/bin/java -jar /home/YOUR_USER_NAME/B4X/B4JPackager11.jar packager.json
- A new directory 'temp' is created - do not delete it!
-
B4X:
cd
- Edit file '.bashrc' (see e.g. step 28 in section 'Making it work'), append these lines, and log out/log in again to activate them:
B4X:
export home="/home/YOUR_USER_NAME"
alias b4jlin="/home/YOUR_USER_NAME/Linuxify/runme.sh"
- Using the text editor, create shell script /home/YOUR_USER_NAME/Linuxify/runme.sh:
B4X:
#!/bin/bash
CURDIR=$PWD
cd /home/YOUR_USER_NAME/Linuxify/temp/build/bin
./java @release_java_modules.txt -Dglass.win.uiScale=100% -m b4j/com.linuxify.main $CURDIR
exit 0
- Make the shell script executable:
B4X:
chmod u+x /home/YOUR_USER_NAME/Linuxify/runme.sh
- Now you're ready to use Linuxify

Usage (on native Linux, i.e. not under Wine):
- Navigate to the directory to which your program's jar and packager.json' files were copied with CopyFilesForLinuxify:
B4X:
cd /home/YOUR_USER_NAME/Documents/B4Jprograms/YOUR_PROGRAMS_DIRECTORY
- Start Linuxify and fill out the necessary data:
B4X:
b4jlin
- Hover the mouse over the views for tooltips
- Click the 'Process' button (it appears once all required data have been entered/selected) to produce your 'linuxified' program
- You'll be able to follow the processing in the TextArea that will appear
- When processing is completed, the 'OK' button appears; click it to hide the TextArea
- The 'Target directory' you have chosen (the default is /home/YOUR_USER_NAME/Documents/B4Jprograms/YOUR_PROGRAM'S_DIRECTORY) will now contain all the required files; cd to it and use './run.command' to start your program

linuxify screenshot.PNG


*** Android SDK Manager ***
As stated on the B4X site, the SDK Manager is no longer needed. However, if you still want/need to use it, here's how to get it to work:

-
B4X:
cp '/home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/Program Files (x86)/Anywhere Software/Basic4android/B4ASdkManager.jar' '/home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java/jdk-11.0.1/bin'

- NOTE: the default installation folder for the 64-bit versions of B4A and B4J is 'Program Files' while the 32-bit versions use 'Program Files (x86)'. Modify the aforementioned path as appropriate, if applicable.

- Now you can run the SDK Manager with these commands, NOT from within the B4A IDE (Note: sdkmanager.bat is at: C:\android\tools\bin\sdkmanager.bat):
B4X:
cd /home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java/jdk-11.0.1/bin
WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" wine ./java.exe -Xmx1G -Dprism.order=j2d --module-path ../javafx/lib/ --add-modules=javafx.fxml,javafx.controls -jar ./B4ASdKManager.jar

- If you prefer a desktop icon to double-click, use Text Editor to create a file (give it extension '.desktop') in /home/YOUR_USER_NAME/Desktop with the following contents:
B4X:
[Desktop Entry]
Name=B4A SDK Mgr
Exec=env WINEPREFIX="/home/YOUR_USER_NAME/virtualwinedrives/b4x64" wine-stable C:\\\\windows\\\\command\\\\start.exe /Unix ./java.exe -Xmx1G -Dprism.order=j2d --module-path ../javafx/lib/ --add-modules=javafx.fxml,javafx.controls -jar ./B4ASdKManager.jar
Type=Application
StartupNotify=true
Path=/home/YOUR_USER_NAME/virtualwinedrives/b4x64/drive_c/java/jdk-11.0.1/bin
Icon=4732_B4A.0
Name[en_US]=B4A SDK Mgr

*** Useful tips ***
- If you don't like the IDE font under Wine, you can change it via Tools->IDE Options->Font Picker.

- Robocopy isn't available for Linux/Wine, so if the CustomBuildAction with Robocopy is present in your project, you'll have to turn it into a comment or replace it with something else. As xcopy.exe does exist in the Wine environment, these lines could be used in a B4XPages project (update the xcopy options "/..." with the ones you prefer):
B4X:
#CustomBuildAction: folders ready, %WINDIR%\System32\xcopy.exe,"..\..\Shared Files" "..\Files" /C /E /F /H /K /R /Y
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\xcopy.exe&args=..\..\Shared+Files&args=..\Files&args=/C&args=/E&args=/F&args=/H&args=/K&args=/R&args=/Y&FilesSync=True

- If you run across the error relating to GLXBadFBConfig when running B4A or B4J, run this in a terminal window (error detail here - thanks to @TheJinJ for this hint):
B4X:
export MESA_GL_VERSION_OVERRIDE=4.5

- Designer works fine in both B4A and B4J, but the WYSIWYG Designer window is completely black (apart from the title bar).

- To use B4X Localizator in a #CustomBuildAction , see this post (thank you, @Ivan Aldaz)

- [B4A] Under Wine, 'Documents' is 'My Documents' (when you use paths in e.g. #CustomBuildActions or in your code).

- [B4J] I've increased the process timeout in my B4J IDE (Tools->IDE Options->Configure Process Timeout) to 600 seconds. Use whatever value suits you best; if a compilation or standalone package build fails with 'process timed out' and you're certain that no process is hanging, increase that value.

- [B4J] If (like I have) a B4J program, running from within the IDE or externally to the IDE under Wine, apparently uses a Greek-looking font (which is actually the 'Standard Symbols' font), see here for a quick fix: https://www.b4x.com/android/forum/t...m-the-ide-uses-greek-font.148952/#post-944544

- [B4J] Msgbox text sometimes seems to be truncated after a couple of lines. I didn't find a solution to this, so here's a workaround I use when I know a long text will have to be displayed:
B4X:
' Was created because at least OpenJDK Java 11 64bit on Linux truncates the MsgBox text (both fx and XUI) after 2 or 3 lines.
' Requires library 'XUI Views'.
' Returns a ResumableSub object.
' Usage:
'     Wait For(MsgBoxLongText(MainForm, 500dip, 300dip, "This is the text", "Here is the title", "Yes", "No", "Cancel", xui.Color_Red)) Complete (result As Int)
'     If Result = xui.DialogResponse_Positive Then ...
Public Sub MsgBoxLongText(frm As Form, width As Int, height As Int, msg As String, title As String, positiveBtnText As String, negativeBtnText As String, cancelBtnText As String, borderColour As Int) As ResumableSub

    Dim fnt14 As B4XFont = xui.CreateDefaultFont(14)
    Dim LongTextTemplate As B4XLongTextTemplate
    Dim dlg As B4XDialog

    dlg.Initialize(frm.RootPane)
    dlg.BackgroundColor = xui.Color_LightGray
    dlg.BlurBackground = True
    dlg.BorderColor = borderColour ' Edit 2021-09-22 - was: "IIf(borderColour < 0, xui.Color_Red, borderColour)", but most XUI.Color_... values are negative
    dlg.ButtonsColor = xui.Color_White
    dlg.ButtonsFont = fnt14
    dlg.ButtonsTextColor = xui.Color_Black
    dlg.Title = title
    dlg.TitleBarColor = xui.Color_White
    dlg.TitleBarFont = fnt14
    dlg.TitleBarTextColor = xui.Color_Black

    LongTextTemplate.Initialize
    LongTextTemplate.Resize(IIf(width > 0, width, 500dip), IIf(height > 0, height, 300dip))
    LongTextTemplate.Text = msg

    Wait For (dlg.ShowTemplate(LongTextTemplate, positiveBtnText, negativeBtnText, cancelBtnText)) Complete (Result As Int)
    Return Result

End Sub

- As my laptop CPU is an AMD Ryzen and the system had intermittently frozen several times while running the IDE-internal B4J packager (this is an issue with Linux and the CPU, not with B4J or Java) I followed the instructions on https://easylinuxtipsproject.blogspot.com/p/bugs.html#ID27 (I could not do the first one as my BIOS config didn't seem to contain the 'PSU Idle Control' option), i.e.:
B4X:
apt install git && git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git && sudo cp -v -u linux-firmware/amdgpu/* /lib/firmware/amdgpu && sudo update-initramfs -uk all
xed admin:///etc/default/grub
[change the line <GRUB_CMDLINE_LINUX=""> to <GRUB_CMDLINE_LINUX="idle=nomwait"> and save the file]
sudo update-grub
sudo reboot
We're a couple of weeks later now, and the PC hasn't been freezing up anymore.

EDITS:
- 2024-09-15: added xcopy alternative suggestions for Robocopy in 'Useful tips'
- 2023-07-16: added a font-related tip to 'Useful tips'
- 2023-06-26: enhanced steps 3 (useful in case a certain error occurs), 9 (small change), and 12 (small change)
- 2023-02-08: added a warning about Wine 8.0.0 in section 'Making it work'
- 2022-07-06: small changes that don't affect the overall instructions
- 2022-06-26: added the 'Screen resolution' value change to step 3 (it will cause the B4J WYSIWYG Designer to be displayed properly)
- 2022-05-23: enhanced sections 'Compiling and running your programs' and 'A semi-automated way to get your B4J UI programs ready' to differentiate the B4J UI programs approach between systems that have/don't have Java installed
- 2022-05-02: added notes about the default B4X installation folders that changed with the arrival of the 64-bit versions
- 2022-03-13: added info about using B4X Localizator in a #CustomBuildAction to 'Useful tips'
- 2022-02-08: added comment about the GLXBadFBConfig error to 'Useful tips'
- 2021-11-15: added comment about Robocopy to 'Useful tips'
- 2021-09-30: added section 'A semi-automated way to get your B4J UI programs ready' and the attached projects
- 2021-09-30: in some references to file '.bashrc', the dot was omitted
- 2021-09-22: small correction in the 'MsgBoxLongText' Sub
 

Attachments

  • linuxify screenshot.PNG
    linuxify screenshot.PNG
    21.1 KB · Views: 722
  • linuxify screenshot.PNG
    linuxify screenshot.PNG
    21.1 KB · Views: 655
  • CopyFilesForLinuxify.zip
    3.1 KB · Views: 652
  • Linuxify.zip
    26.3 KB · Views: 631
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
I tried to install B4A 11 on Linux Mint 20, B4A runs OK, but when compiled the project, got an error

Can not find c:\windows\system32\Robocopy.exe.

Tried to copy that file from my Windows OS, to /my_user_name/virtualwinedrives/b4x64/drive_c/windows/system32,compiled again, still got the same error.

Copied that from Windows OS (c:\windows\syswow64\Robocopy.exe) to /my_user_name/virtualwinedrives/b4x64/drive_c/windows/syswow64, got an error

The program Robocopy.exe has encounter a serious problem and needs to close.

Edit:

Delete this line in B4A Project, solved the problem :
CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
 
Last edited:

johnaaronrose

Active Member
Licensed User
Longtime User
Excellent tutorial. However, somewhere between steps 6 & 14 there should be instructions on how to install B4A.exe itself. I tried:
B4X:
john@johnpc:~/virtualwinedrives/b4x64/drive_c/Program Files (x86)$ wine ./B4A.exe
However, it gave:
B4X:
john@johnpc:~/virtualwinedrives/b4x64/drive_c/Program Files (x86)$ wine ./B4A.exe
wine: created the configuration directory '/home/john/.wine'
0012:err:ole:marshal_object couldn't get IPSFactory buffer for interface {00000131-0000-0000-c000-000000000046}
0012:err:ole:marshal_object couldn't get IPSFactory buffer for interface {6d5140c1-7436-11ce-8034-00aa006009fa}
0012:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hres=0x80004002
0012:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, 80004002
0012:err:ole:get_local_server_stream Failed: 80004002
0014:err:ole:marshal_object couldn't get IPSFactory buffer for interface {00000131-0000-0000-c000-000000000046}
0014:err:ole:marshal_object couldn't get IPSFactory buffer for interface {6d5140c1-7436-11ce-8034-00aa006009fa}
0014:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hres=0x80004002
0014:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, 80004002
0014:err:ole:get_local_server_stream Failed: 80004002
Could not find Wine Gecko. HTML rendering will be disabled.
Could not find Wine Gecko. HTML rendering will be disabled.
wine: configuration in L"/home/john/.wine" has been updated.
0035:err:richedit:ReadStyleSheet skipping optional destination
0035:err:richedit:ReadStyleSheet skipping optional destination
Could not parse file "/home/john/.local/share/applications/epiphany-nostringsfuck.co.uk-4cf0ab6494cb2aae2ca7ebefe47543d99e4b1a9c.desktop": No such file or directory
003d:err:mscoree:CLRRuntimeInfo_GetRuntimeHost Wine Mono is not installed

I guess that I need to install Mono. How do I do that?
 

agraham

Expert
Licensed User
Longtime User

johnaaronrose

Active Member
Licensed User
Longtime User
Thanks Walt. For some inexplicable reason I missed that step out: I think that I thought that it was concerned with B4J installation which I don't want as I'm only interested in Android dev. I last used B4A about 3 years ago and stopped using it as I changed computers to an AMD based desktop from my ancient Intel NUC as that couldn't do Zoom

The thing that I most disliked about B4A was that I ended up with creating a spreadsheet of the pixels that each control/view used in order to put controls/views in their correct places & sizes to work on all phones. Also, I disliked the Basic language one used to code for events: this might have been due to my using Gambas for standalone/client-server apps, which has a superb IDE with its Basic language being object-oriented. I wanted to install B4A as I have an app which I want to revive.

Currently, I'm about to develop another Android app as a Flutter project with Dart coding using Android Visual Studio. I'm not sure whether that or B4A is the better dev environment for Android apps.

PS if you have any questions regarding Ubuntu, please ask me. I don't guarantee to know everything about Ubuntu but I have been using it for over 10 years.
 

johnaaronrose

Active Member
Licensed User
Longtime User
2 questions:

1. I tried putting the adb lines into the .bashrc file and did "source bashrc" and "adb --version" showed the B4X version but I got on Compile & Run after the "Signing Package message:
Installing file to device. Error
* daemon not running; starting now at tcp:5037
could not read ok from ADB Server
* failed to start daemon
error: cannot connect to daemon2.

2. I have a version of adb which is specifically required by AndroidStudio. If I were to add to .bashrc :
B4X:
# Start the Linux version of adb by just typing 'adb'
alias adb='/home/YOUR_USER_NAME/B4X/platform-tools/adb'
it would confuse AndroidStudio which uses adb. Normally I use the version of adb required by AndroidStudio in /usr/bin. I guess that I could change the start of AndroidStudio & of B4A by having separate shell scripts for each with the adb location being set appropriately in each before starting the relevant app. But that seems very messy. Any ideas about a simple solution?
 
Last edited:

walt61

Active Member
Licensed User
Longtime User
Oops, the forum didn't send me a notification mail about the thread being updated.

I take it you did 'source .bashrc' (with the dot prefix) and 'bashrc' in your post was just a typo? Also - probably a silly question but I have to ask - I guess you also tried signing out and in again? (Still reading 'How Linux Works' here, still very much in newbie mode, and thanks for the support offer :)).

I have the impression (from the original post upon which I based mine - https://www.b4x.com/android/forum/t...under-linux-with-wine-fully-functional.98431/) that 'adb' should invoke the specific one for B4A, so as you seem to need another specific one for AndroidStudio, I think indeed setting the correct location for the respective programmes would be the way I'd handle it too and then launch them from shell scripts?
 

johnaaronrose

Active Member
Licensed User
Longtime User
@walt61 You mentioned installing SDK Manager. My guess is that it is required to create emulator "images". Even after installing it, running SDK Manager or AVD Manager from B4A menus only brings up a blank screen titled SDK Manager. Invoking the desktop launcher for B4A SDK Mgr does nothing. Any ideas?
I would like to do that as I'm not impressed by B4A-Bridge which can be a little hit & miss as well as the nuisance of going through answering requests about installing the app (e.g. Play Protect objecting even though I've amended my phone's Android Settings to "Allow installation from unknown sources"). I've also noticed that installing the app allowing overwrite of the existing app on the phone can lead to an unusable app on the phone. IMO B4A should really allow automatic downloading & installation of the app by usb cable: you can do it manually using Terminal but that's a nuisance.
Reviving an old app of mine has lead to a problem with synchronously calling (using library Okhttputils2) code to download a database from the internet. Erel advised putting the code in a Service Module or using B4XPages: to me B4XPages seems the better option as I want a progress bar (on the calling layout's module) updated as the database is downloaded. I haven't been able to find much documentation on converting to B4XPages, except for a youtube video which is about creating a B4XPages app from scratch.
.
Any ideas?
BTW my email address is johndotaarondotroseatgmaildotcom if you wish to ask me any Ubuntu/Linux questions.
 
Last edited:

walt61

Active Member
Licensed User
Longtime User
Hey @johnaaronrose , here we go:

- AVD manager indeed just produces a black window over here, like the built-in SDK manager does. I can't comment on AVD manager as I haven't ever used it. SDK manager was mentioned in Mihai's post, which is why I added it here as a separate section because of @Erel 's recommendation on https://www.b4x.com/b4a.html.

- B4Xpages: highly recommended, it gets rid of all the headaches related to the Android app life cycle and makes code way more straightforward and manageable. Through my 'B4Xgoodies' (see signature) I found 2 threads that might be useful to you to convert 'classic' code to B4Xpages:
I converted several of my own apps to B4Xpages by just
- creating a new project
- with one B4Xpage for each activity I had in the original project
- copy/pasting the code from the original activities to the B4Xpages
- getting rid of the compiler errors and otherwise cleaning up the code (no more Activity_Pause/Resume et al in the B4Xpages)
- and then testing and ironing out anything unforeseen that was left
Perhaps not the most (time-)efficient way, but it worked for me; also, the 'unforeseen' things made me look for answers on the forum and helped me understand why some things were happening (or not).

Hope this helps!
 

johnaaronrose

Active Member
Licensed User
Longtime User
@walt61
I did the step for cp of B4ASdkManager because I'd omitted it earlier. It copied Ok and I started the SdkManager with "WINEPREFIX="/home/john/virtualwinedrives/b4x64" wine ./java.exe -Xmx1G -Dprism.order=j2d --module-path ../javafx/lib/ --add-modules=javafx.fxml,javafx.controls -jar ./B4ASdKManager.jar"". It displayed the window for B4A SDK Manager but when I clicked on "AVD Manager", it gave a popup with "javalang Runtime Exception" & "java.lang reflect.InvocationTargetException". I've googled for that but not found anything. Mihail Raine does not use the AVD Manager as he connects his phones by wifi or by ethernet as they are industrial and have a ethernet socket. Another possibility is to use genymotion to generate emulator images. I can connect by usb but when I try using Ubuntu nautilus to copy the generated apk file to the phone, it gives "libmtp error: Could not send object info". So I seem to be stuck with B4A-Bridge!
Thanks for the useful info about converting a project to B4XPages. One link https://www.b4x.com/android/forum/threads/how-i-converted-my-apps-to-b4xpages.120816/ states that it's very easy to convert an existing project (by presumably doing it in situ) whereas the other https://www.b4x.com/android/forum/threads/conversion-of-b4a-to-b4xpages.136366/ is much more involved and first step is to save existing project with a different name. Which method did you use?
 
Last edited:

walt61

Active Member
Licensed User
Longtime User
AVDmanager does start from the separately installed SDK manager; not an empty black window with that version, but it states "The emulator requires an Intel CPU..." and mine is AMD so I reckon that's as far as I can test it. Perhaps redo all instructions from the SDK manager section in case you overlooked something?

I used neither approach for my B4Xpages conversions: I went with option 3 (the one I mentioned under the 2 links).
 

johnaaronrose

Active Member
Licensed User
Longtime User
@walt61 I'm now trying to convert my existing B4A project to B4XPages. I'm following your second link i.e. the one with many pdf files. All Ok until step 8 instruction 7 (in attached pdf): Bring up your original App and copy the contents of ‘Main’ from the ‘Sub class Globals’ down...Paste over top of Private Sub Button1_Click routine on down. I do that and it then has the original Activity_Create code there. It then says "Remove the Sub Activity_Create(FirstTime As Boolean) line". I do that and it results in all that pasted code not being part of a Sub. Should that code be in Private Sub B4XPage_Created? Also, what about the Sub Activity_Pause coding? Should that be deleted?
In step 9, on compiling I get:
B4X:
Cannot find: C:\windows\System32\Robocopy.exe Please configure paths (Tools - Configure Paths).
But I don't know where Robocopy.exe is and there is no obvious place to refer to Robocopy.exe when I bring up the the Config Paths window. Do you know where Robocopy.exe is and how you refer to it in the Config Paths window?
 

Attachments

  • Section 3 Step 1-11-2.pdf
    501.9 KB · Views: 333

walt61

Active Member
Licensed User
Longtime User
Hi John, yes, just remove methods that aren't applicable to B4Xpages classes (if their code is relevant, use it wherever it's appropriate to do so).

As the 'Useful tips' section in the first post of this here thread states: "Robocopy isn't available for Linux/Wine, so if the CustomBuildAction with Robocopy is present in your project, you'll have to turn it into a comment or replace it with something else."
 

johnaaronrose

Active Member
Licensed User
Longtime User
@walt61 I've done as you said but I want to refer to variable defined as Public in B4XMainPage. I've tried:
Public Main As B4XMainPage = B4XPages.GetPage("B4XMainPage")
with line in Class_Globals of B4XMainPage.
but I get:
Error compiling program.
Error description: Current declaration does not match previous one.
Previous: {Type=Main,Rank=0, RemoteObject=False}
Current: {Type=B4XMainPage,Rank=0, RemoteObject=True}
Error occurred on line: 10
Public Main As B4XMainPage = B4XPages.GetPage("B4XMainPage")
I've also tried Public Main As B4XMainPage
Is putting "Public MainPage As B4XMainPage = B4XPages.GetPage("B4XMainPage")" in each module's Class_Globals the correct way to do it?
I'm now trying to delete the old modules e.g. ChoosePage when I renamed it from Choose, but even though I delete them in B4A's menu or in the directory of the amended project, they keep returning. Is there some mysterious place where they are referenced?
 
Last edited:
Top