OpenCV java.lang.UnsatisfiedLinkError

OpenCV java.lang.UnsatisfiedLinkError

我查看了本网站和其他网站上的其他解决方案,但根本找不到解决我的问题的方法。 3262440

我最初尝试使用来自 OpenCV 的人脸检测示例,并决定简化问题来源限制。

DetectionBasedTracker.java

package com.camgen.facialRecognition;

public class DetectionBasedTracker
{
    public DetectionBasedTracker(String cascadeName, int minFaceSize) {
        helloLog("GO BABY GO");
    }

    private native void helloLog(String logThis);
}

DetectionBasedTracker_jni.cpp

#include <jni.h>
#include <string.h>
#include <android/log.h>

#define DEBUG_TAG "DetectionBasedTracker"

JNIEXPORT void Java_com_camgen_facialRecognition_DetectionBasedTracker_helloLog(JNIEnv * env, jobject, jstring logThis)
{
    jboolean isCopy;
    const char * szLogThis = env->GetStringUTFChars(logThis, &isCopy);

    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);

}

JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt )
    {
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "DetectionBasedTracker:JNI_OnLoad: [%s]", "JNI LOADED");
    return JNI_VERSION_1_2;
    }

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=STATIC

include C:/OpenCV-2.4.10-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES  := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl

LOCAL_MODULE     := detection_based_tracker

include $(BUILD_SHARED_LIBRARY)

日志

...
01-29 11:29:16.885: D/dalvikvm(12816): Trying to load lib /data/data/com.camgen.facialRecognition/lib/libdetection_based_tracker.so 0x40d84598
01-29 11:29:16.885: D/dalvikvm(12816): Added shared lib /data/data/com.camgen.facialRecognition/lib/libdetection_based_tracker.so 0x40d84598
01-29 11:29:16.885: D/DetectionBasedTracker(12816): DetectionBasedTracker:JNI_OnLoad: [JNI LOADED]
...
01-29 11:29:31.430: W/dalvikvm(13375): No implementation found for native Lcom/camgen/facialRecognition/DetectionBasedTracker;.helloLog (Ljava/lang/String;)V
01-29 11:29:31.430: D/AndroidRuntime(13375): Shutting down VM
01-29 11:29:31.430: W/dalvikvm(13375): threadid=1: thread exiting with uncaught exception (group=0x40ab1a08)
01-29 11:29:31.430: E/AndroidRuntime(13375): FATAL EXCEPTION: main
01-29 11:29:31.430: E/AndroidRuntime(13375): java.lang.UnsatisfiedLinkError: helloLog
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.DetectionBasedTracker.helloLog(Native Method)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.DetectionBasedTracker.<init>(DetectionBasedTracker.java:9)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.MainActivity.startNav(MainActivity.java:881)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.MainActivity.fileLoop(MainActivity.java:686)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.CoreFragment.processResult(CoreFragment.java:773)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.CoreFragment$FetchTask.onPostExecute(CoreFragment.java:575)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.camgen.facialRecognition.CoreFragment$FetchTask.onPostExecute(CoreFragment.java:1)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.os.AsyncTask.finish(AsyncTask.java:602)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.os.AsyncTask.access0(AsyncTask.java:156)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.os.Looper.loop(Looper.java:156)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at android.app.ActivityThread.main(ActivityThread.java:5045)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at java.lang.reflect.Method.invokeNative(Native Method)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at java.lang.reflect.Method.invoke(Method.java:511)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-29 11:29:31.430: E/AndroidRuntime(13375):    at dalvik.system.NativeStart.main(Native Method)

正如您从日志中看到的那样,我正在加载已编译的 .so 在调用 JNI_OnLoad 时从 activity 就好了。我包括了我的完整包名,因为我检查了大约 50 次以确保它适合本机调用。我没有东西可以尝试了。

尝试更改此行

JNIEXPORT void Java_com_camgen_facialRecognition_DetectionBasedTracker_helloLog(JNIEnv * env, jobject, jstring logThis)

对此(已更新

extern "C" JNIEXPORT void JNICALL Java_com_camgen_facialRecognition_DetectionBasedTracker_helloLog(JNIEnv * env, jobject, jstring logThis)