简体   繁体   中英

Calling method inside .so shared library on android studio

I need some help to use the method "callMethod()" inside ".so" (shared library) in android studio.

My android studio version is 2.1.3

I created jniLibs folder in "src/main/" Then I created three folders inside jniLibs folder: (armeabi, armeabi-v7a, x86) Then I putted the .so library inside every mentioned folder. After that, I updated the build.gradle as following:

compile fileTree(dir: 'libs', include: ['*.jar','.so'])

In the MainAcrivity java class I wrote this:

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

After that I don't know what should I do?

I need explaining how do I call the method "callMethod()" from the .so library with example please.

I searched a lot but I did't see full example how to do that.

Thanks in advanced.

My Update

I've added to my project new class and native method like below:

@SuppressWarnings("JniMissingFunction")
public class Test1Cpp {
static {
    System.loadLibrary("Cpp");
}

public native String callMethod();
}

Then I can call the method inside .so shared library,

I faced another problem, which is my .so library didn't work with all platform mobiles,

The error is:

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.mysecondtestapp-1/lib/arm/libCpp.so" has unexpected e_machine: 3

So, my question: how to convert my .so library to be worked on all platform mobiles?

I assume that the library does load, otherwise you would get an exception, and I guess you would have mentioned it. So you need to declare the native method you would like to use from the library, and then call it. You can see a simple example here: Sample: hello-jni

The sample source code may be found here: Hello JNI .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM