3

I read in Android Native Development Kit Cookbook that:

By default, Android provides minimal C++ support. There's no Run-time Type Information (RTTI) and C++ exceptions support, and even the C++ standard library support, is partial. The following is a list of the C++ headers supported by Android NDK by default:

cassert, cctype,cerrno, cfloat, climits, cmath, csetjmp, csignal, cstddef, cstdint, cstdio, cstdlib, cstring, ctime, cwchar, new, stl_pair.h, typeinfo, utility

It is possible to add more C++ support by using different C++ libraries. NDK comes with the gabi++, stlport, and gnustl C++ libraries, besides the system default one. In our sample code, we used an external "C" to wrap the C++ method. This is to avoid C++ mangling of the JNI function names. C++ name mangling could change the function names to include type information about parameters, whether the function is virtual or not, and so on. While this enables C++ to link overloaded functions, it breaks the JNI function discovery mechanism.

We can also use the explicit function registration method covered in the Loading native libraries and registering native methods recipe of Chapter 2, Java Native Interface, to get rid of the wrapping.

If RTTI is used in the logic of the application then it will not work on android?

Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

3

You can turn it on, its off by default. To turn it on, add LOCAL_CPPFLAGS += -frtti to your makefile. As usual, code with this flag on will take more memory, be bigger on disk, and be slightly slower than code with it off.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • It does not matter for me :). The core logic is based on RTTI, if it will not work, I am lost. So you say that it can be turned on, but the book says it is **not supported**. What I don't understand is how you can turn on something that is not supported. – Narek Jun 01 '14 at 04:02
  • The book is either out of date or just plain wrong. Android can do RTTI just fine because the compiler it uses, gcc, supports it. THey just turn it off by default- by default they use the -fno_rtti flag to gcc, which turns it off. – Gabe Sechan Jun 01 '14 at 04:18
  • @narek it says **by default** there is no RTTI support: this does not mean you cannot change away from the default settings. – Yakk - Adam Nevraumont Jun 01 '14 at 11:27