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);
extern float fast_log2(float x);.
Since float32 is simply float, on this architecture.
set_get.h file and replace:
Create the Makefile
Android.mk file in the jni folder, containing the instructions to compile libmp3lame on Android.
LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDES += ./include
LOCAL_MODULE := libmp3lame
LOCAL_SRC_FILES := \
LOCAL_LDLIBS := -llog
Then create a
APP_CFLAGS += -DSTDC_HEADERS
Run the build command
jni folder and run
If you everything worked as expected, you should get an output similar to:
Compile thumb : mp3lame <= wrapper.c
SharedLibrary : libmp3lame.so
Install : libmp3lame.so => libs/armeabi/libmp3lame.so
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. ;)