Search code examples
androideclipseandroid-ndkopentok

How to load shared object from location other than armeabi?


I am using the openTok library for video chatting for which libopentok.so file is to be placed into "armeabi" folder under "libs". My project already has jni which places its own folder like armeabi, armeabi-v7 and mips into libs after compilation and replace the armeabi folder containing libopentok.so file.

Please let me know where should I place my .so file and how should I access that file, Thank you


Solution

  • [copy artifacts] into libs after compilation and replace the armeabi folder containing libopentok.so file

    You should not replace the existing folder. Rather, you should place libopentok.so in the same folders as expected by the Android build system.


    Please let me know where should I place my .so file and how should I access that file

    I think you have three options to perform the copy (rather then the replace).

    First, you can copy libopentok.so into the appropriate folder by hand. I used to do this in the past rather than fight with the Android build system. I used to do it with a script that simply gathered up all dependencies, created the directory structure under jni/, and performed the copy.

    Second, you might be able to do it with ant in a pre- or post-build step, but I can't help you with it since I still can't get my head around the XML configuration rules (and the ant man pages suck).

    Third, you can do it with the Android build system. It would look like so in Android.mk. Essentially, Android.mk will have directives/recipes for two components.

    #########################################################
    # OpenTok library
    include $(CLEAR_VARS)
    
    OPENTOK_INCL   := /usr/local/opentok/$(TARGET_ARCH_ABI)/include
    OPENTOK_LIB    := /usr/local/opentok/$(TARGET_ARCH_ABI)/lib
    
    LOCAL_MODULE       := opentok
    LOCAL_SRC_FILES    := $(OPENTOK_LIB)/libopentok.so
    
    LOCAL_EXPORT_CPPFLAGS := -Wno-unused
    LOCAL_EXPORT_C_INCLUDES := $(OPENTOK_INCL)
    
    include $(PREBUILT_SHARED_LIBRARY)
    
    LOCAL_SHARED_LIBRARIES  := opentok
    
    #########################################################
    # MyCoolWarez library
    include $(CLEAR_VARS)
    
    APP_MODULES     := mycoolwarez opentok
    
    # My ass... LOCAL_EXPORT_C_INCLUDES is useless
    LOCAL_C_INCLUDES   := $(OPENTOK_INCL)
    
    LOCAL_CPP_FLAGS    := -Wno-unused
    LOCAL_CPP_FLAGS    += -Wl,--exclude-libs,ALL
    
    LOCAL_LDLIBS            := -llog -landroid
    LOCAL_SHARED_LIBRARIES  := opentok
    
    LOCAL_MODULE    := mycoolwarez
    LOCAL_SRC_FILES := mycoolwarez.c
    
    include $(BUILD_SHARED_LIBRARY)
    

    With the configuration above, the Android build system will copy OpenTok into the same output directory as your library. I believe its due to the APP_MODULES := mycoolwarez opentok line.