izzy
izzy

Reputation: 1349

Android NDK UnsatisfiedLinkError Native method not found

UnsatisfiedLinkError while running a Android NDK app. I have read the Android dev JNI Tips on this error. And as far as I can tell I am doing it correctly. I have also studied the JNI Spec, but it doesn't seem to help. Do I need a JNI_Onload method? I am fairly certain that is optional. Do I need any kind of header for the soundtouch-jni.cpp file? I don't think so.

Basics: package io.hpp.soundtouch , class SoundTouch , Java call to Native Method String getVersionString() , c++ method extern "C" jstring Java_io_hpp_soundtouch_SoundTouch_getVersionString(JNIEnv *env, jobject thiz)

Error Log:

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

This is a copy of the soundtouch-jni.cpp file I am using:

#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);
}

This is a copy of the SoundTouch.java file

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");
    }


}

Upvotes: 0

Views: 3087

Answers (1)

izzy
izzy

Reputation: 1349

I figured it out. Well, not really. I restarted Eclipse and then it worked. Woot Woot!

Upvotes: 2

Related Questions