How to compile libmp3lame 3.100 for Android (2017 update)

LAME is a popular opensource library read and save MP3 files. I’ve recently recently implemented a simple app for Android that records your voice using the microphone to a file.

I initially saved all files to WAV, but their size were not acceptable for internet sharing. So I immediately had the necessity to implement some kind of compression.

Indeed, my choice was to save them to MP3 format.

Even though LAME is not directly available for Android, its compilation is pretty straight forward.

There is a popular tutorial by Samsung that explains how to get it done, but it’s a bit outdated and it doesn’t works properly for the latest releases of LAME.

Here’s an updated guide:

Download Android NDK tools

I used Android NDK r15c, but it should work well with any version.

Don’t forget to add the /path/to/ndk_folder/build directory to your $PATH , so you can run ndk-build from your command line.

Download the last version of Lame

You can find it on their official website. Just download the last tarball and unzip it in the jni folder of your project.

For this guide, I tested with lame v3.100.

Tweak LAME sources to compile on NDK

First of all, find and open the util.h file and replace this line:

extern ieee754_float32_t fast_log2(ieee754_float32_t x);

with this:

extern float fast_log2(float x);.

Since float32 is simply float, on this architecture.

Then find set_get.h file and replace:

#include <lame.h>


#include "lame.h"

Create the Makefile

Create a file in the jni folder, containing the instructions to compile libmp3lame on Android.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += ./include
LOCAL_MODULE     := libmp3lame
./libmp3lame/bitstream.c \
./libmp3lame/encoder.c \
./libmp3lame/fft.c \
./libmp3lame/gain_analysis.c \
./libmp3lame/id3tag.c \
./libmp3lame/lame.c \
./libmp3lame/mpglib_interface.c \
./libmp3lame/newmdct.c \
./libmp3lame/presets.c \
./libmp3lame/psymodel.c \
./libmp3lame/quantize.c \
./libmp3lame/quantize_pvt.c \
./libmp3lame/reservoir.c \
./libmp3lame/set_get.c \
./libmp3lame/tables.c \
./libmp3lame/takehiro.c \
./libmp3lame/util.c \
./libmp3lame/vbrquantize.c \
./libmp3lame/VbrTag.c \

Then create a containing:


Run the build command

Enter the jni folder and run ndk-build.

If you everything worked as expected, you should get an output similar to:

Compile thumb  : mp3lame <= wrapper.c
SharedLibrary :
Install : => libs/armeabi/

Repeated for all architectures (x86, mips, armeabi, armeabiv7a)

I hope this was useful, let me know in the comments if you get any problem with this steps. ;)