libjpeg-turbo for android

KoVadim picture KoVadim · Sep 4, 2012 · Viewed 24k times · Source

I need libjpeg-turbo for android ndk. Did anyone managed to compile it as .a (static) lib? I have tried a few times, but it gave me a lot of errors only.

Answer

Alex Cohn picture Alex Cohn · Sep 6, 2012

Install Android NDK. Following instructions were verified with r8b, older versions may have problems, I don't know.

Get the Android sources for libjpeg-turbo from Benjamin Gaignard:

git clone git://git.linaro.org/people/tomgall/libjpeg-turbo/libjpeg-turbo.git -b linaro-android

In the libjpeg-turbo directory created by git, edit file Android.mk: after line 70, LOCAL_MODULE := libjpeg, add the following:

ifeq ($(notdir $(MAKECMDGOALS)),libjpeg.a)
  LOCAL_SRC_FILES +=  $(libsimd_SOURCES_DIST)
  include $(BUILD_STATIC_LIBRARY)
  include $(CLEAR_VARS)
  LOCAL_MODULE := dummy
endif

Run ndk-build:

ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk obj/local/armeabi/libjpeg.a

Profit!

PS: You may want the armeabi-v7a version:

ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=armeabi-v7a obj/local/armeabi-v7a/libjpeg.a

Or compile for ARM, to improve performance, add to command line:

LOCAL_ARM_MODE=arm

If your target has NEON support, add to command line:

LOCAL_ARM_NEON=true ARCH_ARM_HAVE_NEON=true

UPDATE: to get it work with Android NDK r15 and later, remove all references to libcutils from Android.mk.