Can shared library call another shared library?

别等时光非礼了梦想. 提交于 2019-11-28 09:23:30

I found solution in this way - explicity loading libraries:

    static {
    try {
        System.loadLibrary("DsmShared");
        System.loadLibrary("DsmTestLib");
    }
    catch( UnsatisfiedLinkError e ) {
         System.err.println("Native code library failed to load.\n" + e);
    }
} 
knightwang

Should be:

LOCAL_LDLIBS += -L$(LOCAL_PATH)/libs/
LOCAL_LDLIBS += -lutils

Also don't forget copying libutils.so into your libs/armeabi folder

Vlad Yarovyi

I had the same error . This is how i solved it and maybe you should try this method.

LOCAL_LDLIBS += -L$(LOCAL_PATH)/libs/libutils.so

cyoudatu

No, Android VM will search the so file in its own file systems, but not a folder as [C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib] (I think).

It will search for it from the @androidvm:/system, or other folders specified by java.library.path.

FYI, I just discovered after a long debugging session that the order in which load lib does matter.

    System.loadLibrary("libDsmShared");
    System.loadLibrary("libPINDsmShared");
    System.loadLibrary("DsmTestLib");
  1. First, your Activity have to load all the shared libraries

    static {
        try {
            System.loadLibrary("libDsmShared");
            System.loadLibrary("libPINDsmShared");
            System.loadLibrary("DsmTestLib");
        }
        catch( UnsatisfiedLinkError e ) {
            System.err.println("Native code library failed to load.\n" + e);
        }
    }
    
  2. Include the "lib*.so" when compiling your native code (in the Android.mk) as in

    ...
    LOCAL_LDLIBS := -L/cygdrive/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared -lDsmShared
    LOCAL_LDLIBS += -L/cygdrive/home/android-ndk-r5b/samples/testingDsm/lib/libPINDsmShared -lPINDsmShared
    ...
    
Viktor Apoyan

I found this and test it:

The Android dynamic linker had a bug that prevented this from working, but was fixed in 1.6, I believe. If you use the NDK, use "LOCAL_SHARED_LIBRARIES := libB libC" when defining the libA module. This assumes that libB and libC are also NDK modules that were generated with the NDK.

In case libB.so and libC.so are not generated with the NDK, you should do
the following:
  • in the libA module definition, use LOCAL_LDLIBS += /full/path/to/libB.so /full/path/to/libC.so this ensures that correct symbol exports are generated in libA.so

  • manually copy libB.so and libC.so to $APP_PROJECT/libs/armeabi before rebuilding your .apk, this ensures that it will be copied to /data/data//lib at installation time by the package manager.

now Android.mk have this look:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE           := DsmTestLib
LOCAL_SRC_FILES        := DSM_Library.cpp


#LOCAL_SHARED_LIBRARIES := DsmShared
#LOCAL_SHARED_LIBRARIES += PINDsmShared


# Set local libs with full path.                                                                
LOCAL_LDLIBS := C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so           
LOCAL_LDLIBS += C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libPINDsmShared.so        

include $(BUILD_SHARED_LIBRARY)

but now error

Cannot load library: link_image[1962]: 33 could not load needed library 'C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so' for 'libDsmTestLib.so' (load_library[1104]: Library 'C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so' not found)

occurred, but when I check C:/cygwin/home/android-ndk-r5b/samples/testingDsm/lib/libDsmShared.so this path I found that the library exists there ... What's the metter ?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!