Java – How to import shared libraries in Cmake for Android

How to import shared libraries in Cmake for Android… here is a solution to the problem.

How to import shared libraries in Cmake for Android

I’ve been trying to import a project for Android using CMake, but when I try to import these libraries and compile and execute the program on Android using the terminal, I get the following error:

D/AndroidRuntime( 6162): Shutting down VM
E/AndroidRuntime( 6162): FATAL EXCEPTION: main
E/AndroidRuntime( 6162): Process:, PID: 6162
E/AndroidRuntime( 6162): **java.lang.UnsatisfiedLinkError: dlopen failed: library "" not found**
E/AndroidRuntime( 6162):    at java.lang.Runtime.loadLibrary(
E/AndroidRuntime( 6162):    at java.lang.System.loadLibrary(
E/AndroidRuntime( 6162):    at

My CMakeLists.txt is:

add_library(csoundandroid SHARED IMPORTED)
set_property(TARGET csoundandroid PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)

add_library(sndfile SHARED IMPORTED)
set_property(TARGET sndfile PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)

add_library(c++_shared SHARED IMPORTED)
set_property(TARGET c++_shared PROPERTY IMPORTED_LOCATION /home/ayush/csound-android-6.07.0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi/)
link_directories(/home/ayush/csound-android-6.07. 0/CsoundForAndroid/CsoundAndroid/src/main/jniLibs/armeabi)

target_link_libraries(abc ${LIBS1} ${LIBS2} ${LIBS3} )

Here abc is the generated executable. All the libraries I listed there are in the same place. Can you help me find out what the error is? Any kind of help would be appreciated.


Property IMPORTED_LOCATION should contain the full path to the library file. This is explicitly written in the documentation as that property.

To link with an imported library, use the target name, not the library file:

# Correctly set property for imported library
set_property(TARGET csoundandroid PROPERTY IMPORTED_LOCATION
    /home/ayush/csound-android-6.07.0/(...) /armeabi/

# And correctly link with it
set(LIBS1 csoundandroid)

target_link_libraries(abc ${LIBS1})

Related Problems and Solutions