1

I want to add my library to android-ndk hello-libs example. I reviewed this question and other related questions but they did not solve my issue.

In my CMakeLists.txt I just replaced gperf library (Google sample library) with my library (libgengine.so):

add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
    ${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgengine.so)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frtti -fexceptions")

add_library(hello-libs SHARED
            hello-libs.cpp)

target_include_directories(hello-libs PRIVATE
                           ${distribution_DIR}/gperf/include)

target_link_libraries(hello-libs
                      android
                      lib_gperf
                      log)

Library located like this:

Libraries

The library is built for armeabi-v7a base on readelf command:

armeabi-v7a

Main activity:

static {
        System.loadLibrary("hello-libs");
    }

When I run the app:

java.lang.UnsatisfiedLinkError: dlopen failed: library "/home/user/Downloads/ndk-samples-master/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib/armeabi-v7a/libgengine.so" not found
        at java.lang.Runtime.loadLibrary(Runtime.java:372)
        at java.lang.System.loadLibrary(System.java:1076)
        at com.example.hellolibs.MainActivity.<clinit>(MainActivity.java:36)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1095)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3083)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
        at android.app.ActivityThread.access$1100(ActivityThread.java:221)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:158)
        at android.app.ActivityThread.main(ActivityThread.java:7224)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

The gperf library works well and I can call the functions but when I want to use my library, I get an exception. What is the main problem? The library itself must change or the java code?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Ali Sadeghi
  • 397
  • 4
  • 16
  • Did you check that the file `/home/user/Downloads/ndk-samples-master/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib/armeabi-v7a/libgengine.so` exists? – mkrieger1 Jan 19 '20 at 18:50
  • @mkrieger1 Yes, as I mentioned. The .so file is exists in the directory. – Ali Sadeghi Jan 20 '20 at 08:02
  • Are you sure that `/home/user/Downloads/ndk-samples-master/hello-libs/app/src/main/cpp/../../../../distribution` points to the same location that is shown in the screenshot? – mkrieger1 Jan 20 '20 at 10:01
  • @mkrieger1 Yes. I checked all of these basic things. It's working fine with other .so files. – Ali Sadeghi Jan 20 '20 at 11:06

0 Answers0