Bug? MakeB4XLib - Building libraries by ZIP4j

T201016

Active Member
Licensed User
Longtime User
Hello everyone,

I use in the project:
#AdditionalJar: zip4j-1.3.2 or alternatively zip4j-2.7.0

# AD1 - #AdditionalJar: zip4j-1.3.2
Performing the MakeB4XLIB function creates the .b4xlib library OK,
but I get a message when I open B4J Source code:



# AD2 - #AdditionalJar: zip4j-2.7.0
When performing the MakeB4XLIB function
I get the message:



My question:
- Is there another working version of zip4j?
Any ideas will be appreciated


Example MakeB4XLIB ::
#Region MakeB4XLib
Sub MakeB4XLIB (inDir As String, outDir As String, zipFilename As String) As ResumableSub
Try
    If File.Exists(outDir,zipFilename) Then
        File.Delete(outDir,zipFilename)
    Else
        If inDir.Length = 0 Or outDir.Length = 0 Or zipFilename.Length = 0 Then
            cutils.ShowNotification3("WARNING !", "Fill out the fields required.", cutils.ICON_WARNING, MainForm, "BOTTOM_RIGHT", 2000)
            TextField3.RequestFocus
            Return False
        End If
    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 ci As CheckboxTreeItem In tvFiles.Root.Children
        If ci.Checked Then
            Dim tmpFileName As String = ci.Text.tolowercase
            Dim path As String
            path=File.Combine(TextField1.Text,ci.Text)
            If File.IsDirectory(TextField1.Text,ci.Text) 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
        End If
    Next
    Return True
Catch
    cutils.ShowNotification3("ERROR !", LastException.Message, cutils.ICON_ERROR, MainForm, "BOTTOM_RIGHT", 10000)
    Return False
End Try
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
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
I had a similar problem when trying to automate the building of B4xLibs. See my thread here.

The only ways I found that would work was to either use the JDK as Erel suggested, or call 7zip from the shell (may also work with outer external zip apps but I didn't try any others).

The internal libraries I tried all failed when zipping layout files.

I ended up preferring the JDK option and use this sub to check that it exists:

B4X:
Public Sub JDKPathExists As Boolean
    Dim jHome As String = GetSystemProperty("java.home", "")
    Log(jHome)
    If File.Exists(jHome, "..\bin\jar.exe") Then
        JDKPath = File.Combine(jHome, "..\bin\jar.exe")
        Return True
    Else
        If jHome.EndsWith("jre") = False Then
            jHome = jHome.Replace("jre","jdk")
        End If
        Log("Exists " & File.Combine(File.Combine(jHome,"bin"),"jar.exe") & " : " &  File.Exists(File.Combine(jHome,"bin"),"jar.exe"))
        If File.Exists(File.Combine(jHome,"bin"),"jar.exe") Then
            JDKPath = File.Combine(jHome, "bin/jar.exe")
            Return True
        End If
    End If
    Return False
End Sub

Where jdkpath is a global variable pointing to jar.exe.

Otherwise 7Zip had to be installed

Caveat: I did only run it under java 8 and have not tried under java 11 so may not be too much use to you.

You can see the full code in situ in my project here: https://www.b4x.com/android/forum/threads/create-b4xlib-files-from-projects.111536/
 
Last edited:

T201016

Active Member
Licensed User
Longtime User
Hi, @stevel05
Thank you very much for the professional hint. I will definitely use your beaten paths to solve the above problem. Older versions of zip4J don't work properly, breaking even uncompressed layouts. I figured this out when I manually backed up my files with a regular archiver on hand (it wasn't even Zip7, and the library was working. Zip4J has a specific compression and is not very good for creating our libraries.

I will try both and leave the one that suits me best. Thanks again.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…