There are two main reasons why one would be interested in the Android NDK: first, for performance, and, second, for portability. In the previous chapters, we saw how to access the main native Android APIs from native code for efficiency purposes. In this chapter, we will bring the whole C/C++ ecosystem to Android, well, at least discovering the path, as decades of C/C++ development would be difficult to fit the limited memory of mobile devices anyway! Indeed, C and C++ are still some of the most widely used programming languages nowadays.
In previous NDK releases, portability was limited due to the partial support of C++, especially Exceptions and Run-Time Type Information (RTTI, a basic C++ reflection mechanism to get data types at runtime such as
instanceof
in Java). Any library requiring them could not be ported without modifying their code or installing a custom NDK (the Crystax NDK, rebuilt by the community from official sources, and available at http://www.crystax.net/). Hopefully, many of these restrictions have been lifted since (except wide character support).
Although not necessarily difficult, porting an existing library is not a trivial process. A few APIs might be missed (despite good POSIX support), some #define
directives have to be tweaked, some dependencies have to be ported, as well as dependencies of dependencies. Some libraries will be easy to port, while some other will involve more effort.
In this chapter, in order to port existing code to Android, we are going to learn how to do the following code:
By the end of this chapter, you should understand the native building process and know how to use Makefiles appropriately.
The Standard Template Library is a normalized library of containers, iterators, algorithms, and helper classes to ease most common programming operations, such as dynamic arrays, associative arrays, strings, sorting, and so on. This library gained recognition among developers over the years and is widely spread. Developing in C++ without the STL is like coding with one hand behind your back!
In this first part, let's embed GNU STL in DroidBlaster to ease collection management.
18.219.236.62