我正在尝试使用LAME库在Android中实现MP3编码,遵循以下指南: Lame MP3 Encoder compile for Android http://developer.samsung.com/android/technical-docs/Porting-and-using-LAME-MP3-on-Android-with-JNI
但是我收到一个java.lang.UnsatisfiedLinkError,我认为可能是因为我的包名包含一个下划线,它将其解释为句号。
查看下面的代码可能是这个问题,我该如何解决这个问题。或者是否有其他原因导致这种情况。提前感谢您的帮助。
Record.java :
package co.uk.ing_simmons.aberdeensoundsites;
public class Record extends Activity implements OnClickListener {
static {
System.loadLibrary("mp3lame");
}
private native void initEncoder(int numChannels, int sampleRate, int bitRate, int mode, int quality);
private native void destroyEncoder();
private native int encodeFile(String sourcePath, String targetPath);
[.....]
}
wrapper.c :
void Java_co_uk_ing_simmons_aberdeensoundsites_Record_initEncoder(JNIEnv *env,
jobject jobj, jint in_num_channels, jint in_samplerate, jint in_brate,
jint in_mode, jint in_quality) {
[....]
完整日志cat错误:
04-17 20:58:36.009: E/AndroidRuntime(26768): FATAL EXCEPTION: main
04-17 20:58:36.009: E/AndroidRuntime(26768): java.lang.UnsatisfiedLinkError: initEncoder
04-17 20:58:36.009: E/AndroidRuntime(26768): at co.uk.ing_simmons.aberdeensoundsites.Record.initEncoder(Native Method)
04-17 20:58:36.009: E/AndroidRuntime(26768): at co.uk.ing_simmons.aberdeensoundsites.Record.onCreate(Record.java:79)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.os.Looper.loop(Looper.java:123)
04-17 20:58:36.009: E/AndroidRuntime(26768): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-17 20:58:36.009: E/AndroidRuntime(26768): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 20:58:36.009: E/AndroidRuntime(26768): at java.lang.reflect.Method.invoke(Method.java:507)
04-17 20:58:36.009: E/AndroidRuntime(26768): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-17 20:58:36.009: E/AndroidRuntime(26768): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-17 20:58:36.009: E/AndroidRuntime(26768): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:38)
您应该使用数字1的下划线。因此,如果您的包名称包含ing_simmons,那么您的JNI就会这样形成。
void Java_co_uk_ing_1simmons_aberdeensoundsites_Record_initEncoder
如果在调用的任何其他部分中有下划线,例如Java文件中的类名或方法名,也是如此。
答案 1 :(得分:9)
JNI规范
_1
规则scriptocalypse mentions是JNI spec 8 Chapter 2: Design Overview - Resolving Native Method Names:
Escape Sequence Denotes
_1 the character “_”