Monday, February 28, 2011

Using sysinfo in Android NDK

Sometimes you may need to write a program which needs to query some system information (e.g. system uptime). In this case, one may want to call the sysinfo() with struct sysinfo as defined in <sys/sysinfo.h>. Unfortunately, Android NDK does not provide the sysinfo() definition (definition is included since android-9, but I am still having no luck to link it properly). After some searching, I found this thread provides a solution: adding an assembly source (.S). Build it with your project and it works like a charm. The assembly source is attached below for your reference.

Saturday, February 26, 2011

STLport in Android NDK r5b

Android NDK includes a special version of STLport since r5, and let developers to use it by specifying a flag in files. However, if you are developing using Makefile instead (like I do), using STLport may be a little bit complicated.

First, since the build-standalone-toolchain script of NDK (also included since r5) can only include stdc++ library into the toolchain it builds, compiling with STLport headers may lead to a list of build errors. In order to prevent this, using prebuilt compilers in the NDK ("the hard way" as described in readme) may be a better choice. In this case, you will have to take care with sysroot.

Second, developing with this special STLport has some limitations as mentioned in readme: Exception and RTTI are not supported. Remember to build every cpp source files with -fno-exceptions and -fno-rtti.