How to link mp3lame on Android?

I am attempting to build an Android app which requires MP3 encoding, via DirectLAMEEncoderAudioFormat

Couple of issues neither of which I have been able to solve yet:

  1. If I try and run on the emulator, the linker attempts to link my local version /usr/local/lib/libmp3lame.a. This is annoying, but since I currently only need ARM builds its not a deal breaker.
  2. When I run the app on a device, it crashes on java.lang.UnsatisfiedLinkError: dlopen failed: library "" not found

Initially we had .so builds. I then thought we needed .a builds. Currently I have both .a and .so in the folder pointed at in “Extra Library Search Paths”

Can anyone shed some light on this issue?

Solved it:

Added this to the Projucer section “Extra module’s build.gradle content”

    sourceSets {
        main {
            jniLibs.srcDirs = ['<<path to .so files split by ABI>>']
1 Like

So I managed to get a device build working in debug mode. But now I am trying to generate an app bundle or APK for upload to Google Play I am still hitting the issue where it’s trying to link the static library in /usr/local/lib not the Android dynamic library. I added the following to the “Extra module’s build.gradle content” above:

// Attempt to prevent the local `libmp3lame.a` from being used for an x86_64 build
    packagingOptions {
        pickFirst '<<path to .so files split by ABI>>/x86/'
        pickFirst '<<path to .so files split by ABI>>/x86_64/'
        exclude "/usr/local/lib/**"

…but it still links the local file! If I move/rename the local libmp3lame.a I get

 ninja: error: '/usr/local/lib/libmp3lame.a', needed by
missing and no known rule to make it

Has anyone here successfully used DirectLameEncoderAudioFormat on Android?

I’m working on a similar issue, with another lib (libpd). What does your CMakesLists.txt look like?

Do you maybe have :

add_library( <yourLibraryName>
        IMPORTED )

instead of :

add_library( <yourLibraryName>
        IMPORTED )


1 Like

@adamski Were you able to solve your issue? I’m working my way up to linking a shared library (from a pure Android project to a Juce-Android project), and I still can’t figure out how to configure Projucer to link with a shared lib. I can do it only by editing the generated
CMakeLists.txt file (as pointed out in this thread)

At some point I just renamed the libraries, so there was no confusion with system libs. That worked pretty well.

But appart from that, are you able to link the shared library only by editing the Projucer? No need to edit the CMakeLists.txt after generating your Android project?

Although renaming the libs gets rid of the issue with the linker trying to link to a system lib, it looks like the call to LoadLibrary is in inaccessible Java bytecode, so I cannot rename the library in that call. So for now looks like custom edited CMakeLists.txt might be required. Projucer could offer a field for an alternative name for libmp3lame - that’s assuming that the compiled Java bytecode can accept a parameter set in Projucer…