B4J Question Help with Project Error in Release Mode (SOLVED)

walterf25

Expert
Licensed User
Longtime User
Hi everyone, I have been trying to figure out an issue I am having with a project i've been working on at work, the project consists of many dependencies, but the issue I am seeing is that if I run the project in Debug mode the project runs fine, but when I try to run it in Release Mode, then I get the following error:
io.grpc.StatusRuntimeException: UNKNOWN
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:156)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.keywords.Common$3.run(Common.java:1118)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
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:174)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.nio.channels.UnsupportedAddressTypeException
at java.base/sun.nio.ch.Net.checkAddress(Net.java:136)
at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(SocketChannelImpl.java:727)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:741)
at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:91)
at io.netty.util.internal.SocketUtils$3.run(SocketUtils.java:88)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at io.netty.util.internal.SocketUtils.connect(SocketUtils.java:88)
at io.netty.channel.socket.nio.NioSocketChannel.doConnect(NioSocketChannel.java:322)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:248)
at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1342)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:653)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:632)
at io.netty.channel.ChannelDuplexHandler.connect(ChannelDuplexHandler.java:54)
at io.grpc.netty.WriteBufferingAndExceptionHandler.connect(WriteBufferingAndExceptionHandler.java:157)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:655)
at io.netty.channel.AbstractChannelHandlerContext.access$1000(AbstractChannelHandlerContext.java:61)
at io.netty.channel.AbstractChannelHandlerContext$9.run(AbstractChannelHandlerContext.java:637)
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
Essentially this project makes a call to an internal service to retrieve a list of firmware updates, a jwt token is generated and passed to the gRPC call to authenticate, all of this is working as it should, the problem is when trying to run in Release mode.

I have been doing some research online but so far this link is the only one I have found so far describing something similar to what I am seeing.

Here's the list of dependencies I am using

#AdditionalJar: google-http-client-gson-1.42.1.jar
#AdditionalJar: google-api-client-2.0.0.jar
#AdditionalJar: google-http-client-1.42.3.jar
#AdditionalJar: jackson-annotations-2.14.3.jar
#AdditionalJar: jackson-core-2.14.3.jar
#AdditionalJar: jackson-databind-2.14.3.jar
#AdditionalJar: google-auth-library-oauth2-http-1.23.0.jar
#AdditionalJar: google-api-services-iamcredentials-v1-rev20210813-1.32.1.jar
#AdditionalJar: google-oauth-client-1.34.1.jar
#AdditionalJar: netty-handler-4.1.87.Final.jar
#AdditionalJar: netty-common-4.1.87.Final.jar
#AdditionalJar: netty-buffer-4.1.87.Final.jar
#AdditionalJar: netty-transport-4.1.87.Final.jar
#AdditionalJar: netty-codec-http2-4.1.87.Final.jar
#AdditionalJar: netty-codec-4.1.87.Final.jar
#AdditionalJar: netty-codec-http-4.1.87.Final.jar
#AdditionalJar: netty-resolver-4.1.87.Final.jar
#AdditionalJar: grpc-netty-1.54.1.jar
#AdditionalJar: grpc-api-1.54.1.jar
#AdditionalJar: grpc-context-1.54.1.jar
#AdditionalJar: grpc-core-1.54.1.jar
#AdditionalJar: grpc-stub-1.54.1.jar
#AdditionalJar: grpc-protobuf-1.54.1.jar
#AdditionalJar: grpc-protobuf-lite-1.54.1.jar
#AdditionalJar: protobuf-java-3.22.2.jar
#AdditionalJar: guava-31.1-jre.jar
#AdditionalJar: failureaccess-1.0.1.jar
#AdditionalJar: perfmark-api-0.26.0.jar
#AdditionalJar: netty-transport-native-unix-common-4.1.87.Final.jar
#AdditionalJar: gson-2.9.0.jar
#AdditionalJar: java-jwt-4.0.0.jar

Due to this project being for work I can not share more than what I am providing here, but I would really like to get some help with this, I feel like either I am missing a dependency file or something else is not compatible.

I wish B4J had a way to add a Dependency file similar to a Maven pom.xml file and that it could add or find any dependencies automatically without having to go through all this.

Just FYI, I have created the same project in Eclipse and I am able to run the project just fine, but I'm not sure if Eclipse runs the file in debug mode or release mode, so I really can't compare apples to apples.

Any hints, or advice you guys may have will be very much appreciated, I have been banging my head with this issue for a few weeks without being able to figure out what the root cause of this issue is.

Cheeers,
Walter
 
Solution
I have resolved this issue, turns out I was missing some providers, since this is my first time using gRPC libraries, below is the full PackageProperty entries in case anyone comes across this issue ever.

PackageProperty:
#PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory;
#PackagerProperty: AdditionalModuleInfoString = uses io.grpc.ManagedChannelBuilder;
#PackagerProperty: AdditionalModuleInfoString = uses io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider;
#PackagerProperty: AdditionalModuleInfoString = exports impl.jfxtras.styles.jmetro;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.ManagedChannelProvider with io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider...

walterf25

Expert
Licensed User
Longtime User
I cannot say it based on the error message, but the error might be related to wrong usage of background threads. Make sure not to raise events directly from background threads. You need to use BA.raiseEventFromDifferentThread for this (or JavaObject.CreateEventFromUI).
Hi @Erel On this specific library, I don't raise any events, I have a separate library which is also used in the same project to detect when USB device is inserted or unplugged from the PC, but I am using BA.raiseEventFromDifferentThread, what's weird about this is, is that it runs fine in Debug mode.

Please let me know if you have any other thoughts/suggestions, I am at a dead end if I can't get this project going here at work.

Thanks again! ?
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Probably related: https://stackoverflow.com/questions...ception-but-only-when-packaged-with-shadowjar

Make a test, and run it in release mode without merging the jars.
Ok, so that works fine, If I set the #MergeLibraries: False the project runs fine, but I'm trying to understand why this is, and is there a way to fix it, I need to use the B4JPackager with Inno Setup so I can distribute this project, will all this work without merging all the libraries together?

Thanks,
Walter
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
When the jars are merged all the resources, stored inside those jars, are merged in the the "fat" jar. It can be that there are multiple files with the same name. In some cases it is related to the jars signatures.
It will not work with the packager if it doesn't work when the jars are merged.

You will need to do more searching. Open the jars and find the problematic files.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
When the jars are merged all the resources, stored inside those jars, are merged in the the "fat" jar. It can be that there are multiple files with the same name. In some cases it is related to the jars signatures.
It will not work with the packager if it doesn't work when the jars are merged.

You will need to do more searching. Open the jars and find the problematic files.
Thanks for that information, however this is very frustrating, I've been working on this project for months and need to release a working version.

I understand the issue may not be strictly related to B4J but will there be any tool in the future to make it easier to add dependencies similar to a Maven pom.xml file like in Eclipse? it will really be a big help for those of us who work with big projects that depend in other libraries, I believe it will also save lots of time and will definitely prevent issues such as this one.

Regards,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I was finally able to run the project in Release mode, since the project requires of many dependencies I believe there were some problems with some of the versions, specifically the grpc libraries, I also when through each file and opened each one as a zip archive, deleted the META-INF folder from some of them (Not really sure if this actually made a difference).

I am also able to run the entire project through the B4JPackager and the Inno Setup, and the project compiles and creates the executable just fine.

Now I am seeing a different problem, When I run the project in Release Mode, the project runs fine and I am able to send a gRPC request to our internal service and retrieve a list of firmware updates.

The problem is when I run the Executable file by running run_debug.bat file, the program launches but I see the following error
error: (ProviderNotFoundException) io.grpc.ManagedChannelProvider$ProviderNotFoundException: No functional channel service provider found. Try adding a dependency on the grpc-okhttp, grpc-netty, or grpc-netty-shaded artifact
I have already all these dependencies as can be seen here

List of Dependencies:
#AdditionalJar: google-auth-library-oauth2-http-0.21.1.jar
#AdditionalJar: google-auth-library-credentials-0.18.0.jar
#AdditionalJar: google-http-client-1.32.1.jar
#AdditionalJar: google_http_client_jackson2-1.0.1.jar
#AdditionalJar: protobuf-java-3.22.2.jar
#AdditionalJar: gson-2.9.0.jar
#AdditionalJar: jackson-core-2.13.3.jar
#AdditionalJar: jackson-databind-2.13.3.jar
#AdditionalJar: jackson-annotations-2.13.3.jar
#AdditionalJar: guava-31.1-jre.jar
#AdditionalJar: java-jwt-4.0.0.jar
#AdditionalJar: grpc-auth-1.54.0.jar
#AdditionalJar: grpc-core-1.54.0.jar
#AdditionalJar: grpc-context-1.54.0.jar
#AdditionalJar: grpc-netty-shaded-1.54.0.jar
#AdditionalJar: grpc-api-1.54.0.jar
#AdditionalJar: grpc-protobuf-1.54.0.jar
#AdditionalJar: grpc-protobuf-lite-1.54.0.jar
#AdditionalJar: grpc-stub-1.54.0.jar
#AdditionalJar: annotations-api-6.0.53.jar
#AdditionalJar: failureaccess-1.0.1.jar
#AdditionalJar: perfmark-api-0.26.0.jar
#AdditionalJar: blockhound-1.0.8.RELEASE.jar

I am so close to having everything working and will appreciate any suggestions or advice, I have been burning the candle at both ends with this project and feel that I am finally so close.

Here are a few screenshots of what the project looks like so far.
1721346194102.jpeg



This is when I run the project in Release Mode, but I need it to run the same when creating an executable as well, as you guys can see when running in release mode the list of firmware is retrieved and I don't understand why it would run fine in Release mode but not when running from the executable file created from the B4JPackager and Inno setup.

Cheers,
Walter
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

walterf25

Expert
Licensed User
Longtime User
1. Hopefully this grpc SDK is compatible with Java 9+ modules.
2. If so then you are probably missing a "provides" declaration. You can see an example here: https://www.b4x.com/android/forum/threads/jserver-v4-0-based-on-jetty-11.140437/#content

The providers are usually listed under META-INF/services or something like that. This can be difficult to integrate large SDKs like this.
Hi Erel, thanks for that suggestion, so I included the providers, and now I receive a completely different error:

StackTrace1: b4j/com.snap.hermosabinder.HermosaBinder.getOsVersion(Unknown Source)
StackTrace1: b4j/com.snap.companion.b4xmainpage$ResumableSub_btnrefresh_Click.resume(Unknown Source)
StackTrace1: b4j/com.snap.companion.b4xmainpage._btnrefresh_click(Unknown Source)
StackTrace1: b4j/com.snap.companion.b4xmainpage$ResumableSub_B4XPage_Created.resume(Unknown Source)
StackTrace1: b4j/anywheresoftware.b4a.BA.checkAndRunWaitForEvent(Unknown Source)
StackTrace1: b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
StackTrace1: b4j/anywheresoftware.b4a.BA.raiseEvent(Unknown Source)
StackTrace1: b4j/anywheresoftware.b4a.keywords.Common$3.run(Unknown Source)
StackTrace1: javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
StackTrace1: java.base/java.security.AccessController.doPrivileged(Native Method)
StackTrace1: javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
StackTrace1: javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
StackTrace1: javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
StackTrace1: javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
StackTrace1: java.base/java.lang.Thread.run(Unknown Source)

The Executable gets built successfully, but when I run it with the run_debug.bat I see the above error, I know it must be something simple, but can't figure out what.

These are the lines added with #PackageProperty

Providers:
#PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.ManagedChannelProvider with io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.NameResolverProvider with io.grpc.netty.shaded.io.grpc.netty.UdsNameResolverProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.ServerProvider with io.grpc.netty.shaded.io.grpc.netty.NettyServerProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.LoadBalancerProvider with io.grpc.internal.PickFirstLoadBalancerProvider;
#PackagerProperty: AdditionalModuleInfoString = provides reactor.blockhound.integration.BlockHoundIntegration with io.grpc.netty.shaded.io.netty.util.internal.Hidden.NettyBlockHoundIntegration;

I really appreciate all your help with this, hopefully we can figure this out too.

Regards,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
The error isn't complete.
Here's the full Error
java.lang.RuntimeException: io.grpc.StatusRuntimeException: UNKNOWN
at b4j/anywheresoftware.b4a.keywords.Common$2$1.run(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: io.grpc.StatusRuntimeException: UNKNOWN
at b4j/io.grpc.stub.ClientCalls.toStatusRuntimeException(Unknown Source)
at b4j/io.grpc.stub.ClientCalls.getUnchecked(Unknown Source)
at b4j/io.grpc.stub.ClientCalls.blockingUnaryCall(Unknown Source)
at b4j/com.snap.spectacles.ota.proto.SpectaclesOtaServiceGrpc$SpectaclesOtaServiceBlockingStub.getVersionSet(Unknown Source)
at b4j/com.snap.hermosabinder.HermosaBinder$OTAManager.getVersionSet(Unknown Source)
at b4j/com.snap.hermosabinder.HermosaBinder.getVersionSet(Unknown Source)
at b4j/com.snap.companion.b4xmainpage$ResumableSub_btnrefresh_Click.resume(Unknown Source)
... 8 more
Caused by: java.nio.channels.UnsupportedAddressTypeException
at java.base/sun.nio.ch.Net.checkAddress(Unknown Source)
at java.base/sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.internal.SocketUtils$3.run(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.internal.SocketUtils$3.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at b4j/io.grpc.netty.shaded.io.netty.util.internal.SocketUtils.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel.doConnect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.DefaultChannelPipeline$HeadContext.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeConnect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.ChannelDuplexHandler.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.grpc.netty.WriteBufferingAndExceptionHandler.connect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.invokeConnect(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext.access$1000(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.AbstractChannelHandlerContext$9.run(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.runTask(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(Unknown Source)
at b4j/io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(Unknown Source)
... 1 more

Thanks,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I have resolved this issue, turns out I was missing some providers, since this is my first time using gRPC libraries, below is the full PackageProperty entries in case anyone comes across this issue ever.

PackageProperty:
#PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory;
#PackagerProperty: AdditionalModuleInfoString = uses io.grpc.ManagedChannelBuilder;
#PackagerProperty: AdditionalModuleInfoString = uses io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider;
#PackagerProperty: AdditionalModuleInfoString = exports impl.jfxtras.styles.jmetro;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.ManagedChannelProvider with io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider, io.grpc.netty.shaded.io.grpc.netty.UdsNettyChannelProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.NameResolverProvider with io.grpc.internal.DnsNameResolverProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.ServerProvider with io.grpc.netty.shaded.io.grpc.netty.NettyServerProvider;
#PackagerProperty: AdditionalModuleInfoString = provides io.grpc.LoadBalancerProvider with io.grpc.internal.PickFirstLoadBalancerProvider, io.grpc.util.SecretRoundRobinLoadBalancerProvider.Provider, io.grpc.util.OutlierDetectionLoadBalancerProvider;
#PackagerProperty: AdditionalModuleInfoString = provides reactor.blockhound.integration.BlockHoundIntegration with io.grpc.netty.shaded.io.netty.util.internal.Hidden.NettyBlockHoundIntegration;
 
Upvote 1
Solution
Top