2

I cannot solve this issue even though there are so many similar questions over here, so I decided to post my own problem. A recap:

  1. I compiled my library as a prebuilt shared library (.so) with android-cmake since I was already using cmake for my library. In the cmake, I used gnustl_shared in the ANDROID_STL option (I tried also with stlport_shared but no luck).
  2. I used the native ndk-build compiler. This is my Android.mk file:

    LOCAL_PATH := $(call my-dir)
    
    ### include the lib as a prebuilt lib ###
    include $(CLEAR_VARS)
    
    LOCAL_MODULE            := libOS
    LOCAL_SRC_FILES         := libOS.so
    LOCAL_EXPORT_C_INCLUDES := /home/Dev/libOS/include \
                               /home/Dev/libOS/include/yos/os \
                               /home/Dev/yos/build-arm/generated_include
    
    include $(PREBUILT_SHARED_LIBRARY)
    
    ### build your ndk lib ###
    include $(CLEAR_VARS)
    
    LOCAL_MODULE := hello
    LOCAL_SRC_FILES := main.cpp
    LOCAL_SHARED_LIBRARIES := gnustl_shared libOS
    
    include $(BUILD_SHARED_LIBRARY)
    

    and this is my Application.mk:

    APP_ABI := armeabi-v7a
    APP_STL := gnustl_shared
    APP_MODULES := libOS hello
    APP_PLATFORM := android-19
    
  3. The application compiles properly, and everything is fine. In the moment in which I call the native function, it goes nuts, by throwing at me the following:

    java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZSt24__throw_out_of_range_fmtPKcz" referenced by "libOS.so"...
    

Further, here is a snippet of my MainActivity.java:

static{
    // System.loadLibrary("stlport_shared");
    System.loadLibrary("gnustl_shared");
    System.loadLibrary("libOS");
    System.loadLibrary("hello");
}

public native String hello();

Since I do not really understand what to do, I would really love any help! I also tried with similar questions such as this one android ndk UnsatisfiedLinkError when using a prebuilt shared library but no luck for now.

Thanks in advance for any help!

Community
  • 1
  • 1
alecive
  • 177
  • 1
  • 14
  • I am using android studio. But I disabled the gradle compilation (at least I think I disabled it) by adding the following to the `build.gradle`: `sourceSets.main.jni.srcDirs = [] // disable automatic ndk-build call, which ignore our Android.mk sourceSets.main.jniLibs.srcDir 'src/main/libs'` I also added some more commands I've found online in order for the IDE to directly use `ndk-build` – alecive Jun 06 '15 at 16:46
  • Because as far I understood it was not working with my setup, i.e. a set of prebuilt shared libraries for which I had to define a custom `Android.mk`. Is that wrong? – alecive Jun 06 '15 at 16:58
  • Don't know about Android, but usually the "throw" functions are in libc++. You have to either link your library with that or load it in advance too (or if it doesn't exist on Android, find out what the equivalent is). – user2543253 Jun 08 '15 at 11:42
  • Right now, I am loading and linking with `gnustl_shared`. I already tried with `stlport_shared` library with no luck. Do you think it is worth trying with `c++_shared`? I do not really understand the differences between `stl` and `libc++` honestly. – alecive Jun 10 '15 at 08:29
  • Can you do an `ldd` on libgnustl_shared.so and see if it shows any dependencies? If yes, try to add them to your code. I know STL only as https://en.wikipedia.org/wiki/Standard_Template_Library. I assume in Android it's the same. It doesn't contain the implementation of C++ language features like "throw". These are ususally in some lib*c++*.so – user2543253 Jun 11 '15 at 13:06

0 Answers0