简体   繁体   中英

No Implementation found for native UnsatisfiedLinkError Exception Android JNI

I'm trying to implement LAME for an Android App, but I keep getting the error:

W/dalvikvm(2472): No implementation found for native     Lcom/example/android/audio/util/LameWrapper;.init (IIIII)V

java.lang.UnsatisfiedLinkError: init
     at com.example.android.audio.util.LameWrapper.init(Native Method)
     at com.example.android.audio.util.LameWrapper.init(LameWrapper.java:22)
     at com.example.android.audio.util.Recorder$1.run(Recorder.java:51)

I followed the steps to the answer ( Lame MP3 Encoder compile for Android ). I was able to generate the libmp3lame.so file. It is placed inside /libs/armeabi

I also created Android.mk file:

LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDES := $(LOCAL_PATH)

include $(CLEAR_VARS)

LAME_LIBMP3_DIR := lame-3.99.5_libmp3lame

LOCAL_MODULE    := mp3lame
LOCAL_SRC_FILES := $(LAME_LIBMP3_DIR)/bitstream.c $(LAME_LIBMP3_DIR)/fft.c         $(LAME_LIBMP3_DIR)/id3tag.c $(LAME_LIBMP3_DIR)/mpglib_interface.c $(LAME_LIBMP3_DIR)/presets.c $(LAME_LIBMP3_DIR)/quantize.c $(LAME_LIBMP3_DIR)/reservoir.c $(LAME_LIBMP3_DIR)/tables.c $(LAME_LIBMP3_DIR)/util.c $(LAME_LIBMP3_DIR)/VbrTag.c $(LAME_LIBMP3_DIR)/encoder.c $(LAME_LIBMP3_DIR)/gain_analysis.c $(LAME_LIBMP3_DIR)/lame.c $(LAME_LIBMP3_DIR)/newmdct.c $(LAME_LIBMP3_DIR)/psymodel.c $(LAME_LIBMP3_DIR)/quantize_pvt.c $(LAME_LIBMP3_DIR)/set_get.c $(LAME_LIBMP3_DIR)/takehiro.c $(LAME_LIBMP3_DIR)/vbrquantize.c $(LAME_LIBMP3_DIR)/version.c

include $(BUILD_SHARED_LIBRARY)

I used -javah to create the com_example_android_audio_LameWrapper.h file. I used the .h to create com_example_android_audio_util_LameWrapper.c :

JNIEXPORT void JNICALL Java_com_example_android_audio_util_LameWrapper_init(
    JNIEnv *env, jclass cls, jint inSamplerate, jint outChannel,
    jint outSamplerate, jint outBitrate, jint quality) {
    if (glf != NULL) {
        lame_close(glf);
        glf = NULL;
    }
    glf = lame_init();
    lame_set_in_samplerate(glf, inSamplerate);
    lame_set_num_channels(glf, outChannel);
    lame_set_out_samplerate(glf, outSamplerate);
    lame_set_brate(glf, outBitrate);
    lame_set_quality(glf, quality);
    lame_init_params(glf);
}

The actual java wrapper LameWrapper.java :

public class LameWrapper {
    public static void init(int inSamplerate, int outChannel,
        int outSamplerate, int outBitrate) {
        init(inSamplerate, outChannel, outSamplerate, outBitrate, 7);
    }

    public native static void init(int inSamplerate, int outChannel,
        int outSamplerate, int outBitrate, int quality);

I created a "Recorder.java" object to load in the mp3lame library. The recorder object has a "start" method which calls on the functions from LameWrapper.

public class Recorder {
    static {
    System.loadLibrary("mp3lame");
    }

    public void start(){

        //starts a thread, sets some values

        LameWrapper.init(RECORDER_SAMPLERATE, 2, RECORDER_SAMPLERATE, 32);
    }

I then call on the Recorder object in my MainActivity.

I have searched through much of stack overflow and could not find the answer. Usually for the "no implementation found error", the files are being named incorrectly. However, I am fairly certain I named the packages correctly.

Could someone point me in the right direction? Any help is appreciated. Thank you!

I can see at least one reason why this won't work: your LOCAL_SRC_FILES variable doesn't include com_example_android_audio_util_LameWrapper.c . Fix that, and it should work.

this may help.

search this section No implementation found for native LFoo;.myfunc ()V.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM