我正在尝试为 Android 应用程序实现 LAME,但我不断收到错误消息:
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)
我按照答案的步骤(Lame MP3 Encoder compile for Android)。我能够生成 libmp3lame.so 文件。它被放置在/libs/armeabi
我还创建了Android.mk文件:
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)
我使用-javah创建了com_example_android_audio_LameWrapper.h文件。我使用 .h 创建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);
}
实际的 java 包装器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);
我创建了一个“Recorder.java”对象以加载到 mp3lame 库中。记录器对象有一个“开始”方法,它调用来自 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);
}
然后我在 MainActivity 中调用 Recorder 对象。
我搜索了很多堆栈溢出,但找不到答案。通常对于“未找到实现错误”,文件命名不正确。但是,我相当确定我正确命名了这些包。
有人能指出我正确的方向吗?任何帮助表示赞赏。谢谢!