UnsatisfiedLinkError。我看过the Android dev JNI Tips on this error。据我所知,我正确地做到了。我也研究了JNI Spec,但它似乎没有帮助。我需要JNI_Onload方法吗?我相当肯定这是可选的。我是否需要soundtouch-jni.cpp文件的任何类型的标头?我不这么认为。
基础知识:包io.hpp.soundtouch
,类SoundTouch
,对原生方法String getVersionString()
的Java调用,c ++方法extern "C" jstring Java_io_hpp_soundtouch_SoundTouch_getVersionString(JNIEnv *env, jobject thiz)
错误日志:
06-09 18:11:44.817: D/dalvikvm(4510): Trying to load lib /data/app-lib/io.hpp.starspace-1/libsoundtouch.so 0x41ee0530
06-09 18:11:44.817: D/dalvikvm(4510): Added shared lib /data/app-lib/io.hpp.starspace-1/libsoundtouch.so 0x41ee0530
06-09 18:11:44.817: D/dalvikvm(4510): No JNI_OnLoad found in /data/app-lib/io.hpp.starspace-1/libsoundtouch.so 0x41ee0530, skipping init
06-09 18:11:44.817: W/dalvikvm(4510): No implementation found for native Lio/hpp/soundtouch/SoundTouch;.getVersionString:()Ljava/lang/String;
06-09 18:11:44.817: D/AndroidRuntime(4510): Shutting down VM
06-09 18:11:44.817: W/dalvikvm(4510): threadid=1: thread exiting with uncaught exception (group=0x4160fba8)
06-09 18:11:44.817: E/AndroidRuntime(4510): FATAL EXCEPTION: main
06-09 18:11:44.817: E/AndroidRuntime(4510): Process: io.hpp.starspace, PID: 4510
06-09 18:11:44.817: E/AndroidRuntime(4510): java.lang.UnsatisfiedLinkError: Native method not found: io.hpp.soundtouch.SoundTouch.getVersionString:()Ljava/lang/String;
06-09 18:11:44.817: E/AndroidRuntime(4510): at io.hpp.soundtouch.SoundTouch.getVersionString(Native Method)
06-09 18:11:44.817: E/AndroidRuntime(4510): at io.hpp.starspace.StarSpaceActivity.onCreate(StarSpaceActivity.java:61)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.Activity.performCreate(Activity.java:5231)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.os.Handler.dispatchMessage(Handler.java:102)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.os.Looper.loop(Looper.java:136)
06-09 18:11:44.817: E/AndroidRuntime(4510): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-09 18:11:44.817: E/AndroidRuntime(4510): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 18:11:44.817: E/AndroidRuntime(4510): at java.lang.reflect.Method.invoke(Method.java:515)
06-09 18:11:44.817: E/AndroidRuntime(4510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-09 18:11:44.817: E/AndroidRuntime(4510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-09 18:11:44.817: E/AndroidRuntime(4510): at dalvik.system.NativeStart.main(Native Method)
06-09 18:16:44.870: I/Process(4510): Sending signal. PID: 4510 SIG: 9
这是我正在使用的soundtouch-jni.cpp文件的副本:
#include <jni.h>
#include <android/log.h>
#include "include/SoundTouch.h"
//#define LOGV(...) __android_log_print((int)ANDROID_LOG_INFO, "SOUNDTOUCH", __VA_ARGS__)
//#define LOGV(...)
//#define DLL_PUBLIC __attribute__ ((visibility ("default")))
using namespace soundtouch;
extern "C" jstring Java_io_hpp_soundtouch_SoundTouch_getVersionString(JNIEnv *env, jobject thiz)
{
const char *verStr;
//LOGV("JNI call SoundTouch.getVersionString");
// Call example SoundTouch routine
verStr = SoundTouch::getVersionString();
// return version as string
return env->NewStringUTF(verStr);
}
这是SoundTouch.java文件的副本
package io.hpp.soundtouch;
public final class SoundTouch
{
// Native interface function that returns SoundTouch version string.
// This invokes the native c++ routine defined in "soundtouch-jni.cpp".
public native final String getVersionString();
// Load the native library upon startup
static
{
System.loadLibrary("soundtouch");
}
}
答案 0 :(得分:2)
我明白了。好吧,不是真的。我重新启动Eclipse然后它工作了。 Woot Woot!