简体   繁体   中英

Renaming dependent library in Android NDK causes UnsatisfiedLinkError

I'm developing an android app using Android NDK. The JNI layer of app depends on a shared library 'libDependentLib.so'. My android.mk looks like:

LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
TARGET_PLATFORM := 'android-10'
LOCAL_CPP_EXTENSION := .cpp
LOCAL_CPPFLAGS += -fno-exceptions -fno-rtti         
MY_LOCAL_PATH := $(LOCAL_PATH)/../
LOCAL_LDLIBS := -L$(call host-path, $(MY_LOCAL_PATH)/libs) -lDependentLib
LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)/include-all $(MY_LOCAL_PATH)/include
MY_FILES := abc.cpp xyz.cpp
LOCAL_LDLIBS    += -lm -llog  -lstdc++
LOCAL_SRC_FILES += $(MY_FILES)
LOCAL_MODULE    := jniLayer
include $(BUILD_SHARED_LIBRARY)

My directory structure for libs is:

<Android_Project>
       |
     libs----armeabi-----libjniLayer.so
       |       |---------libstlport_shared.so
       |-----------------libDependentLib.so

Every time I copy libDependentLib.so to armeabi before running the app. Loading of libs is done as:

static {
    try {
        /* loading the libraries */
        System.loadLibrary("stlport_shared");
        System.loadLibrary("DependentLib");
        System.loadLibrary("jniLayer");
    } catch (Throwable th) {
        th.printStackTrace();
    }
}

This runs fine. But due to some requirement, I'm forced to change the external lib name to DependentLib_1. I renamed the same in Android.mk, while loading libs in java and the library name in AndroidProject. But the application fails at System.loadLibrary("jniLayer"); saying

java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1966]:88 could not load needed library 'libDependentLib.so' for 'libjniLayer.so'    (load_library[1108]: Library 'libDependentLib.so' not found)

I'm not able to figure out why still libDependentLib.so is being searched for. I've renamed everything to libDependentLib_1.so. So the same should be looked for. Apart from Andorid.mk and jni loading where libDependentLib.so is being referenced? Note:Android project contains the new lib

Does your libjniLayer.so is dependent on libDependentLib.so?
If so you can't rename libDependentLib.so because when libjniLayer.so is built linker puts name of the dependent .so (libDependentLib.so) in the object code. So if you rename libDepenedentLib.so, jniLayer.so will still be looking for libDependentLib.so.

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