0

Please note that this question is a follow-up question to another question I asked here some time ago.

What would I like to achieve?

I would like to use JNA (version 4.5.2 with Android Studio) to achieve the following:

  1. First I would like to get a list of all callable functions from a given .so file.
  2. Once I have this list, I would like to call a specific function

What did I do so far?

So far, the code of the file "MainActivita.java" of my test app looks as follows:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String MyLibraryString = MyLibrary.Instance.toString();
    }

    public interface MyLibrary extends Library
    {
        MyLibrary Instance = (MyLibrary ) Native.loadLibrary("nameOfMyLibraryWithoutSoExtension", MyLibrary.class);
    }
}

What issues am I facing?

I used to get an error message that my library is not found on my Android device but after putting it in the "jniLibs" subfolder my app seems to be able to detect it. Unfortunately, I now get the error message

java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource path (.)

whenever I try to start the app on my device. I already tried to extract the file "libjnidispatch.so" from the JNA.jar file and put it in its respective subfolders (as described here) but that doesn't work.

The folder structure of the subfolder "app\src\main\jniLibs" of my app looks as follows:

app\src\main\jniLibs\arm64-v8a\myLibrary.so 
... 
app\src\main\jniLibs\arm64-v8a\libjnidispatch.so

app\src\main\jniLibs\armeabi\myLibrary.so 
... 
app\src\main\jniLibs\armeabi\libjnidispatch.so

app\src\main\jniLibs\armeabi-v7a\myLibrary.so 
... 
app\src\main\jniLibs\armeabi-v7a\libjnidispatch.so

app\src\main\jniLibs\mips\myLibrary.so 
... 
app\src\main\jniLibs\mips\libjnidispatch.so

app\src\main\jniLibs\mips64\myLibrary.so 
... 
app\src\main\jniLibs\mips64\libjnidispatch.so

app\src\main\jniLibs\x86\myLibrary.so 
... 
app\src\main\jniLibs\x86\libjnidispatch.so

app\src\main\jniLibs\x86_64\myLibrary.so 
... 
app\src\main\jniLibs\x86_64\libjnidispatch.so

Any help would be highly appreciated.

Hagbard
  • 3,430
  • 5
  • 28
  • 64
  • 1
    Android has specific requirements for any JNI libraries to be loaded in your application. Set the property `jna.debug_load.jna=true` to see where JNA is looking for the jnidispatch library. It uses `System.loadLibrary("jnidispatch")` as its first attempt. Also make sure you've got the libjnidispatch.so for the correct architecture. – technomage Aug 13 '18 at 18:31
  • Thanks a lot for your comment. I enabled this property via "System.setProperty("jna.debug_load.jna", "true");". Unfortunately, I can't find any message related to jnidispatch in logcat. This is the only message I can retrieve when I search for "jni": "10734-10734/? I/art: Late-enabling -Xcheck:jni" – Hagbard Aug 14 '18 at 13:39
  • You'd need to check where android redirects stdout/stderr for a Java process. – technomage Aug 24 '18 at 15:22

0 Answers0