How to link the “lame” mp3 encoder shared object t

2019-08-07 11:00发布

I am trying to write an Android app that uses the Lame mp3 encoder. My development environment is Android Studio 1.1.

Following the hints under Lame MP3 Encoder compile for Android I managed to install the Android NDK and compile Lame. Under /app/src/main/libs/armeabi I obtained the shared object "libmp3lame.so", with

libmp3lame.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped.

However, trying to load this file in a simple Android Studio project, utilizing

static {
    System.loadLibrary("mp3lame");
}

always results in the following error:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/.../base.apk"],nativeLibraryDirectories=[/data/app/.../lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libmp3lame.so"

I also tried to load the file with

System.load(*full file name*);

but this resulted in the same error.

From what I've read so far I assume that this is a gradle issue but I have no clue how to solve that. Any help will be much appreciated!

My Android.mk looks like this

LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE        := libmp3lame
    LOCAL_SRC_FILES     := \
    ./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 \
    ./libmp3lame/version.c

    LOCAL_LDLIBS := -llog

    include $(BUILD_SHARED_LIBRARY)

And this is my build.gradle

apply plugin: 'com.android.application'

android { compileSdkVersion 21 buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "eu.martinloeser.android.lamefromscratch"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}

As I said before, any help will be much appreciated!

2条回答
疯言疯语
2楼-- · 2019-08-07 11:41

wild ass guess...

Your build is not hooking the ndk-build as it should. So.. read up on AS / ndk integration

making changes as he specifies in order to KEEP your Android.mk and not to get shunted off to auto-gen'd make.

Include in your build gradle his stuff to indicate you are not using jni defaults.

Include the explicit step to run the ndk-build against your JNI folder.

See if u dont get a 'libmp3lame.so' in the apk...

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-07 11:44

Thanks for your feedback. I finally got it to work. The key lies inside the 'build.gradle'-file.

In the 'defaultConfig'-section you have to tell Android studio that you want to link lame. Therefore, add

        ndk{
        moduleName "Lame"
        ldLibs "log"
    }

This did the trick for me :-).

Cheers,

Martin

查看更多
登录 后发表回答