Other [new feature] b4xlib - a new type of library

Erel

B4X founder
Staff member
Licensed User
Longtime User
As B4X matures, more and more reusable components are written in B4X directly.
In most cases it is simpler to implement the logic in B4X directly and the code can be cross platform. Especially with the relatively new XUI library.

Standard libraries will never be cross platform as they are compiled to the platform native binary / bytecode. They also have other restrictions related to them being compiled.

Starting with B4A (8.80), B4i (v5.50), B4J (v7.00) and B4R (v3.50), a new type of libraries is available - b4x libraries.

A b4x library is a simple zip file with:

- Code modules. All types are supported including activities and services.
- Files, including layout files.
- Optional manifest file with the following fields:
Version, DependsOn (list of required libraries), Supported Platforms. Fields can be shared between the platforms or be platform specific. For example:
B4X:
Version=2.00
B4J.DependsOn=jXUI, jDateUtils
B4A.DependsOn=XUI, DateUtils
B4i.DependsOn=iXUI, iDateUtils

Files and code modules can also be platform specific.

Creating a b4x library is very simple. You just need to create a zip file with these resources. The zip file extension should be b4xlib. That's all.

Note that the source code can be extracted from a b4x library.

b4x libraries appear like all other libraries in the Libraries tab.

Example of AnotherDatePicker custom view packaged as a b4x library is attached. It is cross platform and using it is a matter of clicking on the library in the list of libraries.
 

Attachments

  • AnotherDatePicker.b4xlib
    9 KB · Views: 4,636
Last edited:

moster67

Expert
Licensed User
Longtime User
What about:
Reserved modules = [B4A: ViewerNetworkService.bas]

In this way, the IDE knows what to load according to platform and we can use one B4XLib to distribute the library.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
In this way, the IDE knows what to load according to platform and we can use one B4XLib to distribute the library.
It is already possible. You have two options:
1. Use conditional compilation in your code:
B4X:
#If B4A
 ...
#end if

2. If you want to add platform specific modules then put them in the platform specific folder. See XUI Views.b4xlib as an example. B4JTextFlow class is only included in the B4J folder.

You should create a single b4xlib. Don't create multiple versions.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Well, I was aware of the first option (which I am already using but was unable to get it working with a B4A Service module.) but did not know about the 2nd option with specific platform modules.
Will try that out. Thanks.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
As B4X matures, more and more reusable components are written in B4X directly.
In most cases it is simpler to implement the logic in B4X directly and the code can be cross platform. Especially with the relatively new XUI library.

Standard libraries will never be cross platform as they are compiled to the platform native binary / bytecode. They also have other restrictions related to them being compiled.

Starting with B4A (8.80), B4i (v5.50) and B4J (v7.00), a new type of libraries is available - b4x libraries.

A b4x library is a simple zip file with:

- Code modules. All types are supported including activities and services.
- Files, including layout files.
- Optional manifest file with the following fields:
Version, DependsOn (list of required libraries), Supported Platforms. Fields can be shared between the platforms or be platform specific. For example:
B4X:
Version=2.00
B4J.DependsOn=jXUI, jDateUtils
B4A.DependsOn=XUI, DateUtils
B4i.DependsOn=iXUI, iDateUtils

Files and code modules can also be platform specific.

Creating a b4x library is very simple. You just need to create a zip file with these resources. The zip file extension should be b4xlib. That's all.

Note that the source code can be extracted from a b4x library.

b4x libraries appear like all other libraries in the Libraries tab.

Example of AnotherDatePicker custom view packaged as a b4x library is attached. It is cross platform and using it is a matter of clicking on the library in the list of libraries.

I am not a prophet but I can see b4x is going to be a single IDE language. How? Erel knows : )
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
That is the final goal and I also have this feeling :)

Regards,

Anand

Nothing prevents (I believe). Now we have B4X libraries.. Cross platform classes..
Most of the b4x language syntax are almost the same.. IDE interface is the same.
If the prophesy is realized the all needed is to select (before start coding) the output target and compile. When select the target then all libs, including internal libraries, that are not supported can be muted or disabled.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can share most of the code between the platforms. This is especially true with XUI library.

The three platforms are quite different and I don't see it as a positive progress to limit developers from being able to use the native features. The current situation is better. You can share code and also write platform specific code.
There is place for improvements. For example, it should be easier to port layouts between the platforms.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It is possible to create an xml file from a b4xlib file with this tool: [Tool] b4xlib - XML generation.
The xml file can be read by the browser.
For all b4xlibs I have published I provide the xml file.
 
Last edited:
Upvote 0

Vader

Well-Known Member
Licensed User
Longtime User
It is possible to create an xml file from a b4xlib file with this tool: [Tool] b4xlib - XML generation.
The xml file can be read by the browser.
For all b4xlibs I have published I provide the xml file.
I have to re-create this for my B4X Browser. I'm starting on it now, but to do it properly will take a while.
 
Upvote 0

Jorge M A

Well-Known Member
Licensed User
Longtime User
I want to share my temporary solution, while @Vader has the time to offer us a definitive one.
  1. I organized my folders similar to how @Erel recommends it here:
    [B4X] Additional libraries folder
  2. Additionally I added the XMLs folder
  3. I take any of the new .b4xlib libraries and place them in the B4X folder.
  4. I generate the XML as indicated by @klaus, and place it in the XMLs folder.
  5. In B4x Object Browser I configure the paths by adding the folder where the XMLs of the new libraries reside.
It works very well for me.

Disadvantage:
B4x Object Browser doesn't know if the .b4xlib is developed for a specific platform. It's up to us to know if it's really cross-platform or not.

1587649247908.png
 
Upvote 0

Vader

Well-Known Member
Licensed User
Longtime User
I also picked up on the fact that we now have cross-language libraries that I need to cater for. I guess you could put the path to the cross-language XML files in each of the property pages? Hmm but then you would think that library is available for all languages :(

I can see another tab in that dialog (Shared?), plus I have to take note of the language (as Erel points out here) and only show that class in the appropriate language "view".
 
Upvote 0

Jorge M A

Well-Known Member
Licensed User
Longtime User
Just as a thought:
Read the Manifest file and interpret the line "Supported Platforms"
Manifest.txt:
Author=Alexander Stolte
Version=1.00
Supported Platforms=B4a,B4j,B4i
B4j.DependsOn=ASTabMenu,ASViewPager
B4a.DependsOn=ASTabMenu,ASViewPager
B4i.DependsOn=ASTabMenu,ASViewPager

Edit: Sorry, that's the same thing you said above.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Encryption might be added in the future. It cannot be encrypted with a global key. Each encrypted library will have its own password.

any news on this point?
it could be very useful, specially for b4i libs. it will save the uploading to hosted builder procedure. like this user can immediately test the lib after an update. less headache for erel :)
 
Upvote 0
Top