Home > database >  IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_aarch_64,
IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_aarch_64,

Time:06-09

I'm trying to run a Java program on a RPi 3B , but when I ran it I got the following error. I tried all the fixes from Failed to load any of the given libraries: [netty-tcnative-linux-x86_64,netty-tcnative], and none of them worked. I tried using Java 11, using a 64 bit OS instead of 32 bit OS, and adding the native netty dependencies (using the latest version). I'm really not sure why can't load the netty_tcnative_linux_aarch64_fedora library, as I specifically imported netty for that specific architecture, and when I run mvn clean package, I can see in the logs that it includes the linux aarch64 libraries in the jar. Is there any other way to make this work? Or am I doing something wrong?

The error:

java.lang. IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_aarch_64,netty_tcnative_linux_aarch_64_fedora,netty_tcnative_aarch_64,netty_tcnative]
at io.grpc.netty.shaded.io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:107)
at io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:705)
at io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:146)
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.defaultSslProvider(GrpcSslContexts.java:230)
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:146)
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:95)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilderSDefaultProtocolNegotiator.newNegotiator(NettyChannelBuilder.java:628)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.buildTransportFactory(NettyChannelBuilder.java:530)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilderSNettyChannelTransportFactoryBuilder.buildclientTransportFactory(NettyChannelBuilder.java:188)
at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:626)
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:297)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:388)
at com.google.api.gax.grpc.ChannelPool.<init>(ChannelPool.java:105)
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:83)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:236)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:230)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:201)

The dependencies (Maven):

<dependency>
          <groupId>io.netty</groupId>
          <artifactId>netty-tcnative</artifactId>
          <version>2.0.52.Final</version>
          <classifier>linux-aarch_64-fedora</classifier>
          <scope>runtime</scope>
      </dependency>

      <dependency>
          <groupId>io.netty</groupId>
          <artifactId>netty-tcnative-boringssl-static</artifactId>
          <version>2.0.52.Final</version>
          <classifier>linux-aarch_64</classifier>
          <scope>runtime</scope>
      </dependency>

      <dependency>
          <groupId>io.netty</groupId>
          <artifactId>netty-handler</artifactId>
          <version>4.1.77.Final</version>
      </dependency>

      <dependency>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-netty-shaded</artifactId>
          <version>1.47.0</version>
      </dependency>

      <dependency>
          <groupId>io.netty</groupId>
          <artifactId>netty-all</artifactId>
          <version>4.1.77.Final</version>
      </dependency>

The logs showing the netty libraries being included in the jar:

[INFO] Including io.netty:netty-tcnative:jar:linux-aarch_64-fedora:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-classes:jar:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-boringssl-static:jar:linux-aarch_64:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-boringssl-static:jar:linux-x86_64:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-boringssl-static:jar:osx-x86_64:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-boringssl-static:jar:osx-aarch_64:2.0.52.Final in the shaded jar.
[INFO] Including io.netty:netty-tcnative-boringssl-static:jar:windows-x86_64:2.0.52.Final in the shaded jar.

Edit: I think I might have gotten it working on the Raspberry pi, but there was another error that required me to switch to Java 8. I didn't know how to switch to Java 8, because somehow the command didn't work, so I switched to a Linux x86-64 distro, where I'm back at the exact same error. I have the libraries imported but they won't load. Does anyone know how to get Java 8 on the Rpi, or how to fix this problem?

Somehow, when I run the program on my aarch64 Mac from command line, it has the exact same error except it still works? I have no idea what is going on

CodePudding user response:

Not a solution, but I have this issue with these versions under SpringBoot 2.6.6 and Java 11, running on Redhat Linux (x64, not ARM). My software works fine under Windows 10 on my laptop. I believe it is related to these notes:

The maven packaging changed a bit in version 2.0.49.Final. The changes were fine for Maven users, but causes some trouble for Gradle and Bazel users. For Gradle, the solution is to explicitly declare the tcnative dependencies with classifiers

from here: https://netty.io/wiki/forked-tomcat-native.html

Now I understand that this refers to packaging and not runtime, and also that Maven works fine (though, in my case packaging was no longer working simply under Gradle), but even with the correct platform tcnative jar in my classpath, I get the same outcome as you have.

Comparing netty-tcnative-2.0.43.Final-linux-x86_64-fedora.jar (which is before the 2.0.49.Final repackaging) with netty-tcnative-2.0.51.Final-linux-x86_64-fedora.jar, the main difference is that the newer packaged only contains a POM file and the native binary, whereas the older library has the binary and a directory of java classes. There is a java class present called:

io.netty.internal.tcnative.Library

And that contains code which loads the binary into memory using:

    private static void loadLibrary(String libraryName) {
        System.loadLibrary(calculatePackagePrefix().replace('.', '_')   libraryName);
    }

Now this class exists in netty-tcnative-classes-2.0.43.Final.jar and also in netty-tcnative-classes-2.0.51.Final.jar, suggesting my supposition above is based on a red herring, but it is the only obvious change in structure I can find between these two library versions.

I'm hoping that someone from the io.netty team can point me in the right direction before I write a hacky static block to load the library myself.

CodePudding user response:

Okay, it turns out that I was very stupid and it was working the whole time. After getting the error, I just waited a bit and it somehow worked. I realized because I tried to run my program from my Mac, which is much faster than the Raspberry Pi, and I realized that it still worked after getting the error, and it only threw the error once. So if anyone else is getting this error, try just waiting, don't abort the program, and see if it works.

  • Related