I am trying to build my Android (native) project using cmake (migrating it from gradle experimental plugin where it used to build and run fine).
I have some native code(will call it 'a') which uses another external prebuilt library code (will call it 'b') and I linked the two like this: (according to https://developer.android.com/studio/projects/configure-cmake)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -frtti -fno-common -fexceptions")
include_directories(
#a's include files' paths
#b's include files' paths)
file(GLOB_RECURSE A_SOURCES
#a's source files' paths)
add_library(a_lib SHARED ${A_SOURCES})
add_library(b_lib SHARED IMPORTED)
set_target_properties(b_lib PROPERTIES IMPORTED_LOCATION "b's .so path")
target_link_libraries(a_lib b_lib)
I got past the compilation and linking steps and the android studio goes ahead to install the APK on my device. However, after launch, the app freezes with the following in the logcat:
E/ExceptionHandler: Uncaught Exception java.lang.UnsatisfiedLinkError: dlopen failed: library "libb_lib.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:989)
at java.lang.System.loadLibrary(System.java:1530)
at com.mm.projectname.model.libloadingclassname.<clinit>(libloadingclassname.java:99)
I know this is happening because b_lib's .so is not there in the apk. And I can see b's symbols along with a's symbols in a's shared library.
So my question is how can I
- either package my prebuilt b's .so in the apk
- or prevent the system from looking for b.so in the libs folder and make it look for b's symbols in a's .so only.
I searched a lot for similar posts and questions (eg one and two ) but i cant get anything to work. I am really looking for the right way to do this - which wont create problems in the future (like changing the targetSDKversion). I also tried building the prebuilt lib with the latest ndk version.
It's possible that I am doing a very small mistake, and would really appreciate if someone could point it out.
Thanks in advance