3

I have a simple question, but very specific.

I built in a c++ project (non-android) a shared library .so which I'm using for others projects.

I want to use it now to develop an Android app with Android NDK. In the /app/src/main/jni folder, I have the cpp file and I would like to use the functions of my library. Here the content of the .cpp file

#include <string.h>
#include <jni.h>
#include <mysharedlibrary.h>

jstring
Java_com_example_nativeapp_MyActivity_stringFromJNI( JNIEnv* env,
                                                jobject thiz ) {

      ObjectFromSharedLibrary obj;
      functionFromSharedLibrary(obj);
      ...

}

But I really don't know how to do it. I spent the last 2 day looking for an answer but I found nothing

Here my environment:

  1. OS Linux Ubuntu 14.04 LTS
  2. Android studio 1.5
  3. Gradle 2.8
  4. my .so is located in /usr/local/lib and *.h in /usr/local/include/mysharedlibraryname/

I want to know if it's possible and how to do it properly from scratch.

Thanks in advance

Thomas BRAUD
  • 111
  • 1
  • 2
  • 5
  • This link might help http://stackoverflow.com/questions/16705954/adding-a-so-file-in-android-studio – Rohit Nov 26 '15 at 04:25
  • You cannot use a library from your `/usr/local/lib` on Android OS. And this is not only the difference of platforms (your Linux runs on 64bit x86, Android is typically 32bit ARM v7a). It is also the runtime environment. You can usually recompile a Linux library with Android toolchain with little effort, but your mileage may vary. – Alex Cohn Nov 26 '15 at 11:35
  • Did you find the answer? I have same problem – Anton Shkurenko Nov 26 '15 at 11:53
  • No I haven't found anything for the moment, I'm still working on it. – Thomas BRAUD Nov 27 '15 at 03:00

1 Answers1

3

First build your .so shared libraries using eclipse . Now add Your generated *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs. As shown in this Link

Community
  • 1
  • 1
Rohit
  • 122
  • 9