Arjun
Arjun

Reputation: 197

java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++.so" not found

I am trying to use two prebuilt native libraries (.so) in my Android application. For this i have created a JNI project where i have done the following,

  1. Created a java native library and compiled with javac
  2. Created a C header with javah -jni command
  3. Created a corresponding C source file where the methods are implemented
  4. This C source code (the methods in it) will refer to the methods that .so file expose
  5. Android.mk file is written. It is given below.
  6. Using ndk-build it is built and then pushed to the mobile

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := libmodule1
LOCAL_SRC_FILES := prebuilts/$(TARGET_ARCH_ABI)/libmodule1.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE    := libmodule2
LOCAL_SRC_FILES := prebuilts/$(TARGET_ARCH_ABI)/libmodule2.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE    := com_example_androidwrapper_NativeLibrary
LOCAL_SRC_FILES := com_example_androidwrapper_NativeLibrary.c
LOCAL_SHARED_LIBRARIES := libmodule1 libmodule2 
include $(BUILD_SHARED_LIBRARY)

When i run this app I am getting the following error.

java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++.so" not found

If i dont load the module1, module2 libraries app will work fine (i commented out the calls to the methods exposed by these two modules and rewrote the Android.mk file to just to build a shared library and not to use any prebuilt ones) This is working fine.

Any help is appreciated. Thanks.

I had successfully used the prebuilt .so files from a native application which i ran in the same target device. When i changed the application.mk "APP_ABI := all" It gave me the following error.

[x86_64] Prebuilt       : module1.so <= jni/
[x86_64] Install        : module1.so => libs/x86_64/module1.so
C:/Users/user/AppData/Local/Android/android-ndk-r12b/build//../toolchains/x86_64-4.9/prebuilt/windows/bin/x86_64-linux-android-strip: Un
able to recognise the format of the input file `./libs/x86_64/module1.so'
make: *** [libs/x86_64/module1.so] Error 1
make: *** Deleting file `libs/x86_64/module1.so'

I think the prebuilt .so files are supposed to run in the arm64-v8a itself.

Upvotes: 1

Views: 8190

Answers (1)

Dan Albert
Dan Albert

Reputation: 10509

What is libmodule1.so? It sounds like it's a library that you pulled off an android device and are trying to use. That's pretty much only going to work for the exact device you pulled it from.

As for the second part, it sounds like the libraries in your x86_64 directory aren't actually x86_64 libraries. Try $NDK/toolchains/x86_64-4.9/prebuilt/$YOUR_OS/bin/x86_64-linux-android-readelf -h module1.so. It will print the ELF header for the library. One of the lines should be:

Machine:                           Advanced Micro Devices X86-64

If the value of machine is anything else, it's not an x86_64 library.

Upvotes: 1

Related Questions