hydraulic-software / conveyor

Gradle plugin, user guide and discussion forums for Conveyor
https://conveyor.hydraulic.dev
Apache License 2.0
123 stars 10 forks source link

Native libraries rewrite #40

Closed manosbatsis closed 2 years ago

manosbatsis commented 2 years ago

The documentation states that native shared/JNI libraries are moved out of the JAR. This seems to create an issue for us with MongoDB's Realm Database, as it's JNI bits only use System.loadLibrary for Android and not our desktop JVM app. Naturally we get an exception the one bellow. I'll add a issue to Realm's github, but was wondering if there is a workaround this one from our/conveyor's side in the mean time?

Caused by: java.lang.RuntimeException: Couldn't load Realm native libraries
        at io.realm.kotlin.internal.interop.realmc.<clinit>(realmc.java:28)
        ... 85 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.realm.kotlin.internal.interop.realmc.<clinit>(realmc.java:26)
        ... 85 more
Caused by: java.lang.NullPointerException: lib must not be null
        at io.realm.kotlin.jvm.SoLoader.unpackAndInstall(SoLoader.kt:98)
        at io.realm.kotlin.jvm.SoLoader.load(SoLoader.kt:62)
        at io.realm.kotlin.jvm.SoLoader.load(SoLoader.kt:47)
        ... 90 more
mikehearn commented 2 years ago

You can turn off the extraction, but the problem is that then the libraries won't be automatically signed, and of course your app will spam the user's home directory in places that won't get cleaned up on uninstall. You can try setting app.jvm.extract-native-libraries = false but it's a global setting, you can't set it just for specific JARs.

It might be easier to just quickly fork Realm and fix the JNI code so that instead of detecting Android it tries loadLibrary first and does the extraction in an exception handler. That's a more normal way to do it. You could then submit the fix as a PR?

manosbatsis commented 2 years ago

Realm devs have responded on the above issue but i'm not sure on the best approach to suggest in a reply. They do check an FS location before trying extraction from JAR. Perhaps a system/env property could be used by realm or something, would really appreciate it if you could have a quick look at their reply.

manosbatsis commented 2 years ago

Thank you Mike, closing this one.