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:
The library is built for armeabi-v7a base on readelf command:
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?