Hi, Does anyone have any experience using JNI to call native C/C++ libraries in Android? Is the environment suitable for running C/C++ libraries and if so is there anything specific about the environment which you need to accommodate? Thanks
My understanding is that Android provides only a subset of the standard C++ runtime library. For example, Android does not support exceptions in native code. I think there are other restrictions as well.
One complication is that, while Android itself might include many native libraries, only some of them are considered stable enough to link against. The Android NDK page lists the libraries which are safe.
- libc (C library) headers
- libm (math library) headers
- JNI interface headers
- libz (Zlib compression) headers
- liblog (Android logging) header
- A Minimal set of headers for C++ support
If your C library only uses those, you should be fine. C++ support sounds a little spottier.
for a C library, you shouldn't have any trouble. a C++ library might be more fun if it uses much of the standard library, because most of the C++ standard library is missing, but you can always supply your own "mini-STL". that's basically how external/webkit works.
much of Android's java.util.regex, java.nio.charset, java.util, and java.text are implemented by calling ICU4C, for example. (the library's in external/icu4c and the JNI is in dalvik/libcore/icu/src/main/native.) a mix of ICU's C and C++ interfaces are used, so you can rest assured this stuff gets quite a good workout on a daily basis ;-)