简体   繁体   中英

How to link Android NDK shared library?

I can build an produce all platform shared library. I have a makefile name Android.mk as:

 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := com_masum_test_JniTest.c
 LOCAL_MODULE := com_masum_test_JniTest
 include $(BUILD_SHARED_LIBRARY) 

Another file named Application.mk as:

APP_ABI := all

When I enter command ndk-build it creates all shared library.

But when I call native function I get exception as :-

09-11 15:57:02.018 22949-22949/com.masum.test E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.masum.test, PID: 22949 java.lang.IllegalStateException: Could not execute method of the activity

Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.masum.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.masum.test-1/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libcom_masum_test_JniTest.so"

I don't even see the lib folder in my work space. Check the pic:- 在此处输入图片说明

File explorer:-

在此处输入图片说明

Clearly my application cannot link with the shared library. So how to link?

I found a way to link. If I make a directory named jniLibs inside app/src/main and then copy all the share library in side. It is able to link and load library. Note that directory name "jniLibs" is case sensitive.

You must call this in source code:-

static{
    System.loadLibrary("libray_name"); // without prefix 'lib' and suffix '.so' i.e. "libLibName.so" should be only LibName. 
}

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