Introduction
This chapter explains how to port existing popular C/C++ libraries to Android using Android NDK. These libraries are widely used to implement feature-rich applications with graphics, sounds, and physical simulations entirely in C++. There is not much fun in simply compiling libraries. So, the parts related to FreeImage, FreeType, and Box2D provide minimal samples to demonstrate the functionality of each library. Audio and networking libraries are discussed in greater detail in the subsequent chapters. We will show you how to compile libraries and, of course, give some short samples and hints on how to start using them.
Typical caveats for porting libraries across different processors and operating systems are memory access (structure alignment/padding), byte-order (endianness), calling conventions, and floating-point issues. All the libraries described below address these issues quite well, and even if some of them do not officially support Android NDK, fixing this is just a matter of a few compiler switches.
To build any of the mentioned libraries, we need to create makefile for the Windows version and a pair of the Android.mk
and the Application.mk
files for Android NDK. The source files of the library are compiled to object files. A collection of object files is combined into an archive, which is also called a static library. Later, this static library can be passed as an input to the linker. We start with the Windows version because the Android.mk
and Application.mk
files are built on top of standard makefiles.