I have a dynamic linked library (.so) built for general Linux platforms usage (x86, armv7a), now I’m going to port the library for Android usage.
What I expect is to open the general shared libraries by dlopen in the JNI library’s CPP code so that I only need to develop a few JNI functions to bridge the exported functions of the original library.
This is all for avoid rebuilding whole codes of the original library. There are a large number of source files and the structure is very complicated. Otherwise I have to rewrite the makefile for NDK building for them.
I put the original library and JNI library together in location
/data/data/com.example.myapp/lib in the device’s root file system (I use the emulator in Android Studio, the tool will copy .so files in project’s
lib folder automatically in installation).
The following I use adt to login the android’s shell and issued
file command to list the files in the
generic_x86_arm:/data/data/com.example.myapp/lib # file * libSmart.so: ELF shared object, 32-bit LSB 386, BuildID=179c89de2ebe921fe1b9be6e78e83148f3781568, stripped libmain.so: ELF shared object, 32-bit LSB 386, for Android 16, built by NDK r21e (7075529), BuildID=6b395607222185aac9c163dc205b26add1ab55c4, stripped
- libSmart.so: The original library I built for general Linux platforms
- libmain.so: The JNI library which will called by JAVA of android activity.
I can open libSmart.so by
fopen(), but can’t open it by
dlopen() which it returns NULL.
Is there some constraints to do these? Or is any libraries used in Android (even not directly called by JAVA) must be built with JNI?
Source: Windows Questions C++