-3

I have *.so file, which is not generated by me in my project. I know that there is a function in this lib named 'x', and I want to use this function, but don't know how..

P.S.

I don't have source files that used for generating *.so file.

Hrach
  • 3
  • 2
  • big info about lib – Hrach Jul 18 '18 at 11:45
  • 030d470 d _ZZNK2cv20CvtColorLoop_InvokerINS_10RGBA2mRGBAIhEEEclERKNS_5RangeEE25__cv_trace_location_fn279 003306b4 b _ZZNK2cv20CvtColorLoop_InvokerINS_10RGBA2mRGBAIhEEEclERKNS_5RangeEE31__cv_trace_location_extra_fn279 0030d4a4 d _ZZNK2cv20CvtColorLoop_InvokerINS_10mRGBA2RGBAIhEEEclERKNS_5RangeEE25__cv_trace_location_fn279 003306b8 b _ZZNK2cv20CvtColorLoop_InvokerINS_10mRGBA2RGBAIhEEEclERKNS_5RangeEE31__cv_trace_location_extra_fn279 0030cb8c d _ZZNK2cv20CvtColorLoop_InvokerINS_11Gray2RGB5x5EEclERKNS_5RangeEE25__cv_trace_location_fn279 0032f9ec b _ZZNK2cv20CvtColorLoop_I........ – Hrach Jul 18 '18 at 11:53

1 Answers1

1

First, you need absolutly the header (.h) containing the function declaration.

Secondly, you have to create a folder that contains your .so file, you can name it for example jniLibs and put it in src/main/jniLibs, then add the sourceSets to you gradle file, into the android block :

sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/jniLibs']
        }
    }

NOTE : the jniLibs folder normally contains subfolders depending on the lib's target ABI (arm64-v8a, armeabi-v7a, x86, x86_64), so you have to know it.

And finally you have to load the native library in the java side by adding :

   /*  Load jni .so on initialization */
    static {
        System.loadLibrary("my-native-lib-name");
    }

And declare your function to use it like below :

public static native void myFunction(String arg, int another_arg);
E.Abdel
  • 1,992
  • 1
  • 13
  • 24
  • Thanks for the answer. I did all this, but the problem in this, I don't know what type return myFunction and what kind of argument take it. – Hrach Jul 18 '18 at 11:32
  • 1
    Unfortunately, If you don't have the header then it is very difficult to do – E.Abdel Jul 18 '18 at 11:47
  • Even if I had this header file, how I can connect my java function or JNI function to this function which exists in .so file? I think in this file we have C or C++ function, and want call this function. – Hrach Jul 18 '18 at 11:58
  • If you have the .h, so you have to follow the step by step in my answer or this answer to load it into the native side : https://stackoverflow.com/questions/45314478/how-to-load-native-library-into-native-android-code-androidstudio/50507825#50507825 – E.Abdel Jul 18 '18 at 12:02
  • Another thing, you don't connect your java function to the native function, but you declare (same name, same params) your C/C++ function in the java side as a native function and you call it through JNI – E.Abdel Jul 18 '18 at 12:08