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,627
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
No news.

I don't think that you really need to worry about it. You can sell the library to developers. It is not very likely that someone will distribute the source code.
Unfortunately @Erel is not like that. I'm sorry to contradict you, I would have preferred it to be as you wished.

It happened to me that I have not been opened, modified and redistributed with another name. And the guilty person to whom I pointed out what he told me as an answer ... "If you didn't want others to modify and rename your library, you shouldn't distribute it in b4xlib, you should have waited for it." He also took offense at my complaints and accused me of being presumptuous and megalomaniac.

Since then I have no longer distributed b4xlib
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If someone posts a b4xlib in the forum, which is heavily based on your code, and refuses to give you credit then I will delete the library and if needed delete the disrespecting user account.
You can read everything I told you in the forum. In any case it was not distributed in the forum with another name but privately.

It is not very important to me, because if he had asked I would have also allowed to make changes.
The problem, as you have already pointed out, is a lack of respect. And unfortunately that cannot be eliminated with computer science. Respect is in people's hearts.

Having said that a method of protection would be welcome
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
As I had pointed out, the simple fact that the libs are "readable" makes them too easy to alter, misuse, steal credit and even break the intented usage.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I don't think that you really need to worry about it. You can sell the library to developers. It is not very likely that someone will distribute the source code.

i am not worry about that erel, my point was that each time a user update his lib YOU as the administrator needs to upload the lib to the hosted builder. sometimes it can take more then 1 update to get the lib running (as you can see in this thread: https://www.b4x.com/android/forum/threads/iqbimagepicker-multiple-selection-image-picker.103780/) i am lucky that i have a local builder so i can test it immediately when a new version is uploaded to the thread but not everyone has a local mac. so it is basically a benefit for you. maybe you can add a way to upload an updated version of a lib to the hosted builder by us ? this could also cut the waiting time until a lib is uploaded to the hosted builder. you will not need anymore to deal with user libraries. :)
 
Upvote 0

MathiasM

Active Member
Licensed User
I'm making my feet wet with this type of library, is it possible to 'hide' a library for the user?
I have a 'core' class which other classes rely on, but is not meant to be used directly. It would only confuse the user of my library to see the class and the methods in it.

I noticed that Erel commented on this thread, pointing to the 'new' b4xlib. But I don't see how hiding would work with b4xlib.
 
Last edited:
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
I have been using B4A since 2014 and happy with that, now I am trying to catch everything that I did not included in my software (like b4xpages) and now b4xlib

I use the alt+5 compile to library heavily, it is very easy this way.. however I see that it will be b4a only (in case using b4a)

And I need it to be cross platform so i understood that i need to use b4xlib for that.

What I am missing is, if there is a easy way to edit and package the p4xlib, since I am used to edit my libraries frequently and it is going to be frustrating needing to copy the source file each time to the b4xlib zip file.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
As the .b4j (Main) is not included in a b4xlib, you may use a snippet like this in it and then just press F5 to rebuild:

zip4j-1.3.2: see attachement and put it in your Libraries folder.

B4X:
#Region Project Attributes 
    #MainFormWidth: 600
    #MainFormHeight: 600 
    #AdditionalJar: zip4j-1.3.2
#End Region

Sub Process_Globals
    
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    
    #If Release
        MakeB4XLIB(File.GetFileParent(File.DirApp), "K:\B4J\AddLibraries", "AnotherDatePicker.b4xlib")    
        Log("done!")
    #end if    
    
    ExitApplication
End Sub

#Region MakeB4XLib
Sub MakeB4XLIB(inDir As String,outDir As String,zipFilename As String)
    If File.Exists(outDir,zipFilename) Then
        File.Delete(outDir,zipFilename)
    End If
    Dim zipFile As JavaObject
    zipFile.InitializeNewInstance("net.lingala.zip4j.core.ZipFile",Array(File.Combine(outDir,zipFilename)))
    Dim constants As JavaObject
    constants.InitializeStatic("net.lingala.zip4j.util.Zip4jConstants")
    Dim params As JavaObject
    params.InitializeNewInstance("net.lingala.zip4j.model.ZipParameters",Null)
    params.RunMethod("setCompressionMethod",Array(constants.GetField("COMP_DEFLATE")))
    params.RunMethod("setCompressionLevel",Array(constants.GetField("DEFLATE_LEVEL_NORMAL")))
    For Each filename As String In File.ListFiles(inDir)
        Dim tmpFileName As String = filename.tolowercase
        Dim path As String
        path=File.Combine(inDir,filename)
        If File.IsDirectory(inDir,filename) And tmpFileName = "files" Then
            zipFile.RunMethod("addFolder",Array(path,params))
        Else
            If tmpFileName.EndsWith(".bas") Or tmpFileName = "manifest.txt" Then
                zipFile.RunMethod("addFile",Array(getFile(path),params))
            End If
        End If
    Next
End Sub

Sub getFile(path As String) As JavaObject
    Dim fileJO As JavaObject
    fileJO.InitializeNewInstance("java.io.File",Array(path))
    Return fileJO
End Sub
#End Region

Alwaysbusy
 

Attachments

  • zip4j-1.3.2.zip
    120.3 KB · Views: 357
Upvote 0
Top