Notes on Compiling Various C Libraries for the Android NDK
It’s not so easy! You can’t just use the “./configure and make” build system most libraries come with. Instead, at the very least you’re going to have to create your own custom “Android.mk”, which lists the .c files you need and sets up gcc correctly.
Well, that’s the best-case scenario. Some libraries require some minimal patching or other trickery. Here are my notes for some.
- Conveniently comes with a ready-made “Android.mk” in the main directory, as well as a demo application under “android-project”.
- However... if you run “./configure” even once, it will regenerate “SDL_config.h” and ruin it for Android builds. Be sure to use a freshly downloaded version of the file.
- Comes with an Android.mk, which can also compile in its dependencies.
- However, I needed to patch it a bit to work with newer versions of libogg and libvorbis. In particular, you can do without the -DOGG_USE_TREMOR gcc flag.
- You need a “config_types.h” header file, but this can only be generated if you run “./configure”. I did so on Linux (x64) and it seems to work fine for Android builds.
- You need a “pnglibconf.h” header file. There’s one you can use in the distribution, in “scripts/pnglibconf.h.prebuilt”.
- gcc flags are different for x86 and ARM platforms. Here’s what I used in Android.mk:
ifeq ($(TARGET_ARCH),x86) LOCAL_CFLAGS := -DPACKAGE="pixman" -D_USE_MATH_DEFINES -DPIXMAN_NO_TLS -DUSE_X86_MMX -DUSE_SSE2 else LOCAL_CFLAGS := -DPACKAGE="pixman" -D_USE_MATH_DEFINES -DPIXMAN_NO_TLS -DUSE_ARM_NEON -DUSE_ARM_SIMD endif
- You need a “pixman_version.h” header file, but this can only be generated if you run “./configure”. I did so on Linux (x64) and it seems to work fine for Android builds.
- The “pixman-implementation.c” code tries to load all implementations, but this will fail on compilation if the implementations are not there. I patched the “_pixman_choose_implementation” function like so:
#if defined(USE_ARM_SIMD) || defined(USE_ARM_NEON) || defined(USE_ARM_IWMMXT) imp = _pixman_arm_get_implementations (imp); #else imp = _pixman_x86_get_implementations (imp); #endif //imp = _pixman_ppc_get_implementations (imp); //imp = _pixman_mips_get_implementations (imp);
- gcc flags: -DPACKAGE_VERSION=“cairo” -DCAIRO_NO_MUTEX -DHAVE_STDINT_H -DHAVE_UINT64_T
- You need “cairo-features.h” and “cairo-version.h” header files, but they can only be generated if you run “./configure”. I did so on Linux (x64) and it seems to work fine for Android builds.
- “cairo-output-stream.c” won’t compile due to Android’s less-than-Posix implementation of localization. You need to patch the “_cairo_dtostr” function:
#ifndef __ANDROID__ struct lconv *locale_data; #endif ... #ifndef __ANDROID__ locale_data = localeconv (); decimal_point = locale_data->decimal_point; #else decimal_point = "."; #endif
(I’ve opened a bug about this.)
- gcc flags: -DLUA_ANSI
- Again, a problem with Android’s less-than-Posix implementation of localization. You need to patch “luaconf.h”. Simple add this at the bottom:
#ifdef __ANDROID__ #define getlocaledecpoint() ('.') #endif
See also this Stack Overflow post.
- gcc flags: -DE4C_THREADSAFE -DMISSING_PTHREAD_CANCEL
- gcc flags: -DSIMCLIST_NO_DUMPRESTORE