tags:

views:

122

answers:

2

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

+2  A: 

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.

Daniel Yankowsky
Thanks for your answer Daniel. I've also just read that the native Dalvik core code is written in C/C++ and also uses the JNI bridge. This is similar to the work I want to do so I'm hopeful that I can write JNI calls to C libraries in my Android app.
Trossachs
A: 

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 ;-)

Elliott Hughes