运行Android NDK应用程序时发生UnsatisfiedLinkError。我已阅读the Android dev JNI Tips on this error。据我所知,我做得正确。我还研究了JNI Spec,但似乎无济于事。我需要一个JNI_Onload方法吗?我相当确定这是可选的。 soundtouch-jni.cpp文件需要任何标题吗?我不这么认为。

基础知识:包io.hpp.soundtouch,类SoundTouch,Java调用本机方法String getVersionString(),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");
    }


}

最佳答案

我想到了。好吧,不是真的。我重新启动了Eclipse,然后它起作用了。呜呜呜!

09-13 14:08