B4J Question MergeLibraries break my lib

Pendrush

Well-Known Member
Licensed User
Longtime User
#MergeLibraries: False = I can run app in Release mode
#MergeLibraries: True = App crash in Release mode

Stacktrace:
java.lang.RuntimeException: java.lang.StringIndexOutOfBoundsException: Range [0, -1) out of bounds for length 7
at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1052)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.StringIndexOutOfBoundsException: Range [0, -1) out of bounds for length 7
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)
at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4602)
at java.base/java.lang.String.substring(String.java:2715)
at org.openqa.selenium.manager.SeleniumManager.<init>(SeleniumManager.java:81)
at org.openqa.selenium.manager.SeleniumManager.getInstance(SeleniumManager.java:107)
at org.openqa.selenium.remote.service.DriverFinder.<init>(DriverFinder.java:45)
at org.openqa.selenium.chrome.ChromeDriver.generateExecutor(ChromeDriver.java:98)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)
at com.pendrush.selenium.kotlin.SeleniumLib.initialize(SeleniumLib.kt:42)
at com.pendrush.selenium.Wrapper.initialize2(Wrapper.java:80)
at com.pendrush.selenium.Wrapper.Initialize(Wrapper.java:76)
at b4j.example.main$ResumableSub_AppStart.resume(main.java:92)
at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1050)
... 7 more

Line 42 in wrapper lib:
Java:
private val options = ChromeOptions() // <- global declaration
driver = ChromeDriver(options)        // <- error line 42 from stacktrace: at com.pendrush.selenium.kotlin.SeleniumLib.initialize(SeleniumLib.kt:42)

The error is completely unrelated... I cannot get it.

This behavior also create unusable app with standalone package.

Library:

I need to build standalone package, any solution?
 
Solution
Example of adding a file to a merged jar during "build standalone package":
B4X:
#CustomBuildAction: before packager, %JAVABIN%\jar.exe, uf BCTextInCLV.jar -C C:\Users\H\Downloads Files\1.txt

The file is located in C:\Users\H\Downloads\Files\1.txt and it will be included in the jar under Files\1.txt.
BCTextInCLV.jar is the name of this app.

My test worked. I was able to read the file. I'm not 100% sure that it will work with the META-INF file, after it is packed.

Pendrush

Well-Known Member
Licensed User
Longtime User
After some research, I found that some files from my library were not copied into the JAR file that was compiled in release mode with flag #MergeLibraries: True.
If I copy ALL the files from my kotlin-selenium-all.jar library, WITHOUT overwriting, into the compiled JAR everything works fine.

You can also see the difference in the size of the files, it is obvious that something is also missing in the Release JAR:

My Library:
B4X:
Pnd_Selenium.xml              70,210
Pnd_Selenium.jar               6,457
kotlin-selenium-all.jar   30,139,004

Release JAR (#MergeLibraries: True):
B4X:
Selenium7.jar             26,156,717

Any solution?
 
Last edited:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
2940 Files are missing in Release Jar.
PDF with folders and file names is attached to this post.
 

Attachments

  • 2940MissingFilesInReleaseJar.zip
    454 KB · Views: 172
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Simple copy missing files from META-INF subfolder make app to work as it should.

EDIT:
Only one file make app to work on path: META-INF\selenium-build.properties

Is there any chance to make app in release mode and somehow to instruct B4J to include this file?
 
Last edited:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
File is used inside library:

also here:
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example of adding a file to a merged jar during "build standalone package":
B4X:
#CustomBuildAction: before packager, %JAVABIN%\jar.exe, uf BCTextInCLV.jar -C C:\Users\H\Downloads Files\1.txt

The file is located in C:\Users\H\Downloads\Files\1.txt and it will be included in the jar under Files\1.txt.
BCTextInCLV.jar is the name of this app.

My test worked. I was able to read the file. I'm not 100% sure that it will work with the META-INF file, after it is packed.
 
Upvote 0
Solution

Pendrush

Well-Known Member
Licensed User
Longtime User
\META-INF\selenium-build.properties - folder and file inside project Files folder

Solution for: build standalone package
B4X:
#CustomBuildAction: before packager, %JAVABIN%\jar.exe, uf Selenium16.jar -C e:\B4J\_WRAP\Selenium\Selenium16\Files META-INF\selenium-build.properties


Solution for: compile app in release mode with #MergeLibraries: True
B4X:
#CustomBuildAction: 2, %JAVABIN%\jar.exe, uf Selenium15.jar -C e:\B4J\_WRAP\Selenium\Selenium15\Files META-INF\selenium-build.properties
 
Last edited:
Upvote 0
Top