Using JNA with ReactNative Android App results in "Native Library (com/sun/jna/android-aarch64/libjnidispatch.so" not found in resource path (.)

1,036 views
Skip to first unread message

Flippy

unread,
Oct 27, 2022, 8:25:34 AM10/27/22
to Java Native Access
I postet my detailed question on stackoverflow:

My problem is when using jna to bridge from c/c++ .so I receive "could not invoke MyCaller.testFunc because libjnidispatch.so not found in resource path (.)"

It neither works if I add the jna.jar file via Android Studio (build.gradle, dependencies{...}) "implementation files('libs/jna-5.12.1.jar')" or if I directly add it with gradle using "implementation 'net.java.dev.jna:jna:5.12.1'".

I also set the source path in android{...} to
SourceSets{
   main {
      jniLibs.srcDirs = ['src/main/jniLibs']
   }
}

I placed the jna.jar inside of android/app/libs and added the missing android-* (e.g. android-aarch64) folder with their libjnidispatch.so. I got the android-aarch64.jar files from the github repository, and changed them to folders.
I also added the android-* folders to android/app/src/main/jniLibs with their full names and only with the architecture (e.g. android-aarch64 and aarch64).

My custom .so file is also located in this folder "android/app/src/main/jniLibs".

Do I have to set any other path?

Matthias Bläsing

unread,
Oct 27, 2022, 12:48:12 PM10/27/22
to jna-...@googlegroups.com
Hi,

using JNA on android is already covered on stackoverflow:

https://stackoverflow.com/questions/36305914/setting-up-jna-in-android-studio

and in the JNA FAQ:

https://github.com/java-native-access/jna/blob/master/www/FrequentlyAskedQuestions.md#jna-on-android

Hope that helps

Matthias
> --
> You received this message because you are subscribed to the Google
> Groups "Java Native Access" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to jna-users+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jna-users/69a1143e-0a94-439a-a666-a49674f853edn%40googlegroups.com
> .

Message has been deleted

Matthias Bläsing

unread,
Oct 28, 2022, 3:47:34 PM10/28/22
to jna-...@googlegroups.com
Am Freitag, dem 28.10.2022 um 00:25 -0700 schrieb Flippy:
> the @aar trick after implementation files ('libs/jna.5.12.1.jar@aar')
> did the trick for me, thank you!
> Now my library can't be found even if I use
> System.setProperty("jna.library.path", "/absolute/path/to/so")
> and using
> SourceSets main.jniLibs.srcDirs ['src/main/jniLibs'].
>
> I placed my .so to app/src/main/jniLibs/. In this folder I placed the
> .so and I also have folders for each architecture "aarch64" and
> "android-aarch64" consisting the so. Also I placed the all of the
> contents to app/libs.
>
> "Unable to load library 'testlib':
> dlopen failed: library "libtestlib.so" not found
> dlopen failed: library "libtestlib.so" not found
> dlopen failed: library "libtestlib.so" not found
> Native library (android-aarch64/libtestlib.so) not found in resource
> path (.)

This is not a JNA question. Figure out how to properly bundle a native
library on android. On android loading from classpath WILL FAIL. You
have to bundle the native library correctly.

Maybe this:

https://proandroiddev.com/reducing-apk-size-by-using-abi-filters-and-apk-split-74a68a885f4e

and this (see "Include prebuilt native libraries")

https://developer.android.com/studio/projects/gradle-external-native-builds

and this

https://stackoverflow.com/questions/56902428/cant-add-a-so-library-in-android-studio-jnilibs-directory-dont-work

and

https://gist.github.com/TheMobileBridge/d4c831e5c38651f73a9ba92dc4c93cfe

can help

Matthias
Reply all
Reply to author
Forward
0 new messages