Android is a Linux-based operating system with a different libc and some specific conventions regarding library and symbol versioning.


In order to build Libav targeting Android the native sdk is required. The NDK provides multiple compilers.

The general cross-compilation rules do apply. Additional extra cflags and ldflags could be needed depending on the NDK in use.

From Libav 11 the --target-os can be set to android to automatically generate the unversioned shared objects without symbol versions.

The additional cflags and ldflags are still needed.

In order to support Android M you need a recent version or use the linux --target-os.


The following instructions assume the NDK toolchain are in your PATH if they are not you may change the --cross-prefix to factor in the full path.

ECFLAGS="-march=armv7-a -mfloat-abi=softfp"
ARCH_SPECIFIC="--arch=arm --cpu=armv7-a --cross-prefix=arm-linux-androideabi-"
./configure ${ARCH_SPECIFIC} --target-os=linux --sysroot="$SYSROOT" --extra-cflags="$ECFLAGS" --extra-ldflags="$ELDFLAGS" --enable-shared --disable-symver


The following instructions assume you are using a Linux distribution, change the paths to fit your specific OS as needed.

ECFLAGS="-target armv7-none-linux-androideabi -gcc-toolchain ${NDK}/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 -mfloat-abi=softfp -Wno-asm-operand-widths"
ELDFLAGS="-target armv7-none-linux-androideabi -gcc-toolchain ${NDK}/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 -Wl,--fix-cortex-a8"

./configure --arch=arm --cpu=armv7-a --cross-prefix=arm-linux-androideabi- --cc=clang --target-os=linux --sysroot="$SYSROOT" --extra-cflags="$ECFLAGS" --extra-ldflags="$ELDFLAGS" --enable-shared --disable-symver


The java library loading facility does not recursively load the libraries.

You must load the libraries in order:

  • avutil, avresample, avcodec, avformat

Using from the Native Code

With Android L the native binaries MUST be position-independent.

In order to generate valid binaries -pie must be passed to configure.

  • --extra-ldexeflags=-pie

Using from Dalvik/Java

The simplest way to integrate using jni is to put the libraries in your jni directory and add to the the following lines.

The following snippet assumes that the libraries and the includes live in a libav subdirectory.

define LIBAV_LIB
    include $(CLEAR_VARS)
    LOCAL_MODULE := $(1)
    LOCAL_SRC_FILES := libav/lib/lib$(1).so
    LOCAL_EXPORT_C_INCLUDES := libav/include

LIBAV_LIBS = avutil avresample avcodec avformat avfilter

$(foreach VAR,$(LIBAV_LIBS), \
        $(eval $(call LIBAV_LIB,$(VAR))))

Then use the LOCAL_SHARED_LIBRARIES to add them to the link line of your software.

include $(CLEAR_VARS)
LOCAL_MODULE    := player
LOCAL_SRC_FILES := player.c
LOCAL_LDLIBS :=  -llog
LOCAL_SHARED_LIBRARIES := avformat avcodec avresample avutil

Javacpp bindigs

There are bindings available as javacpp-presets