I'm building a shared library for use in a Java app using the Android NDK. Using readelf
to inspect the lib/armeabi-v7a/libXXXlib.so
file generated by a release build, it appears to contain all the symbols (function, variable names) of my native C/C++ code.
Indeed, the shared object file appears to be identical for the debug and release builds. (The only difference in the output in the libs
folder being whether or not the gsb.setup
and gdbserver
files are created.) I'm overriding the optimisation set by the NDK with an APP_CFLAGS += -O3
in my Application.mk
, but I wouldn't expect the release build to generate debug symbols by including the -g
flag, which it does.
I found a comment on SO stating 'In both cases, debug and release, it leaves the -g flag in because, to quote the comment, "we generate symbol versions of the binaries that are later stripped when they are copied to the final project's libs/ directory"', and another stating: 'JNI cannot find the functions for java if they don't have names.'
ndk-build
is certainly stripping something from the obj/armeabi-v7a/libXXXlib.so
file, as that is much larger than the one eventually created in libs
, but it still seems to be leaving all my functions' and variables' names intact in the file.
Are all my functions' names required by JNI (rather than just the entry-points into the native code)?
If not, how can I remove the symbols which are not required?
The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.
libc++ LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop, and as of NDK r18 is the only STL available in the NDK. Note: For full details of the expected level of C++ library support for any given version, see the C++14 Status, C++17 Status, and C++20 Status pages.
On Android, it is possible to use the Mobile SDK native API from an NDK library instead of the Java API. To use the native API, you must call TasInitialize with two extra parameters: the JNI environment and the application context. Both are passed as parameters to each JNI native method.
Feel free to set default visibility=hidden, and set attribute visibility=default for the few functions you need to export (similar to DLLEXPORT) in Windows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With