fiskaly / fiskaly-sdk-java

fiskaly Cloud-TSE SDK for Java/JRE and Java/Android
MIT License
4 stars 0 forks source link

Mac dylib not found #17

Closed cjaentsch closed 4 years ago

cjaentsch commented 4 years ago

I get the following exception when trying to load the dylib for MacOS (v.1.2.000):

The path seems to be built incorrectly (double "dylib.dylib").

Suppressed: java.lang.UnsatisfiedLinkError: dlopen(libcom.fiskaly.client-darwin-amd64-v1.2.000.dylib.dylib, 9): image not found
        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
        ... 34 more
    Suppressed: java.lang.UnsatisfiedLinkError: dlopen(libcom.fiskaly.client-darwin-amd64-v1.2.000.dylib.dylib, 9): image not found
        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204)
        ... 34 more
prempador commented 4 years ago

Thanks, I just checked. We build the path correct, without the duplicate. Seems to be an issue somewhere else. I need to look into it some more.

cjaentsch commented 4 years ago

Thanks, I just checked. We build the path correct, without the duplicate. Seems to be an issue somewhere else. I need to look into it some more.

Maybe on MacOS you don't need to add the ".dylib" when calling Native.register...

prempador commented 4 years ago

Thanks, I just checked. We build the path correct, without the duplicate. Seems to be an issue somewhere else. I need to look into it some more.

Maybe on MacOS you don't need to add the ".dylib" when calling Native.register...

Tried that as well, didn't work.

cjaentsch commented 4 years ago

Ok, but you can reproduce it? So it's not an error just in our environment?

prempador commented 4 years ago

Ok, but you can reproduce it? So it's not an error just in our environment?

Yes, I am able to reproduce, and I will work on a fix.

cjaentsch commented 4 years ago

Seems to be the libName not starting with "lib" triggers the following function in NativeLibrary.mapSharedLibraryName:

Bildschirmfoto 2020-06-16 um 17 03 00

... which leads the "name" to have another ".dylib" appended.

Bildschirmfoto 2020-06-16 um 17 03 25
prempador commented 4 years ago

Yep, just came to the same conclusion. But changing the dylib name just for JNA sounds kinda dirty to me.

prempador commented 4 years ago

But it looks like the problem kinda lies with Java itself. https://www.tutorialspoint.com/java/lang/system_maplibraryname.htm

prempador commented 4 years ago

I found a workaround for now. This would only work if the .dylib is in System.getProperty("user.dir").


static {
    String libName = getLibName();
    if (Platform.isMac()) {
      libName = System.getProperty("user.dir") + "/" + libName;
    }
    setLibSearchPath();
    Native.register(ClientLibrary.class, libName);
  }
cjaentsch commented 4 years ago

Strange JAVA behaviour... In our case the dylib is located in the "jna.library.path", so the workaround wouldn't work.

prempador commented 4 years ago

So, the workaround will be that we provide a .dylib specially for Java named "libcom.fiskaly.client-darwin-amd64-v1.2.000.dylib" and remove the dylib extension from our path builder. I tested this, and this works for sure. Expect changes by tomorrow or the day after.

cjaentsch commented 4 years ago

Works already when renaming the file to "libcom.fiskaly.client-darwin-amd64-v1.2.000.dylib.dylib". But still, strange Java logic.