Search code examples
androidandroid-studionative-code

Use .so library in Android Studio 0.8.2


I tested All previously shown answers on stackoverflow more than once. None of them working. I use Android Studio 0.8.2 with the latest Gradle Version.

I have libfourier.so. This is a native library made in .c.

I don't have any other files.

It has been used in a previous app and did work.

I need this library because it can perform fast fourier transform without the input being a power of 2.

Is this possible? If yes, how?

Currently I have put the libfourier.so in /libs/armeabi/libfourier.so

And I call it by using

static {  
    System.loadLibrary("fourier");  
}  

But I get an UnsatisfiedLinkException stating the library could not be found.


Solution

  • There is no real magic. Just put it in libs/armeabi/libfourier.so like every other library.

    Everybody saying otherwise is wrong.

    First of all, the library was immediately found on a real device. So emulators in Android Device Manager and Genymotion cannot find this libraries apparently. Or the application is not installed as *.apk.

    For the diehards, it is certainly possible to install the apk-file. But for the lazy ones like me, a real device will do the trick.

    Secondly, you have to make sure your package name corresponds in the native function in the native code with the call to the native function in the android code.

    If you have in Android intec.ugent.be.MyClass.nativeMethod() than your native method should be named: Java_intec_ugent_be_MyClass_nativeMethod(..). This is the case if you do not use JNI_onLoad in your native library.

    Of course you have than to rebuild the jni-package with ndk-build. And add the new so-file to libs/armeabi.

    So I would advice if you work with NATIVE CODE/LIBRARY just use a REAL device to RUN TEST DEBUG (do not forget to enable debugging on the device)