In the hope that it might be useful for someone else out there, here are the steps that I use to build FreeImage for Android. These instructions were written for FreeImage 3.15.4 and NDK r8d. Using other versions of FreeImage or the NDK build system may require changes.
Download the FreeImage source distribution.
Setup the NDK project. Due to the size of FreeImage, it makes a lot of sense to compile it separately, rather than including it directly within your project. That's the approach taken here.
ndk-buildwill attempt to compile code located within a folder named jni, that gives us the following structure:
FreeImageAndroid -- jni -- Android.mk -- Application.mk -- [FreeImage source]
The shared library is defined simply to make sure that the static library is built. Without it, the build system will infer that the static library isn't been used, and won't compile it.
Pretty simple, the only thing you might want to change is the
APP_ABIfield, depending on the platform you want to target.
Before you can compile the code successfully, there are a few minor tweaks you'll have to make:
Since the NDK doesn't include
search.h, you'll need to remove the following define from Source/LibTIFF4/tif_config.h:
Note that although the answer to this StackOverflow question states that you need to define
lfind, that's not actually the case. In 2009, LibTIFF switched from using
lfindto its own local equivalent. That renders the above configuration option unneccessary, since
search.his never used anywhere else.
ndk-buildwithin the top-level FreeImageAndroid folder. At the start of the post, I mentioned that these steps are designed to work with NDK r8d. While NDK r8e is available, it has a bug that prevents it from compiling FreeImage successfully.
Once the build has finished, you can extract libFreeImage.a from the obj folder and include it in your own project.