简体   繁体   English

尝试使用JNI组件启动Android + OpenCV文件时出现困惑的UnsatisfiedLinkError

[英]Perplexing UnsatisfiedLinkError when attempting to launch Android + OpenCV file with JNI component

Apologies if my answer already lies somewhere on the Internet, but I have been at this for days now and there simply does not seem to exist an answer to my problems. 抱歉,如果我的答案已经存在于Internet上的某个位置,但是我已经呆了好几天了,而对于我的问题似乎根本不存在答案。 I have looked at most other similar questions posted by other users, and I have tried every solution that has been offered, but it stubbornly refuses to work. 我查看了其他用户发布的大多数其他类似问题,并且尝试了所提供的每种解决方案,但都顽固地拒绝了。

I've been trying to get a simple Android + OpenCV + JNI code running. 我一直在尝试运行一个简单的Android + OpenCV + JNI代码。 I have configured all the necessary settings, including the Android & Application .mk files and I have also made sure all my OpenCV libraries are correctly imported, which they seem to be. 我已经配置了所有必需的设置,包括Android&Application .mk文件,并且还确保正确导入了我的所有OpenCV库,它们似乎是正确的。 My code does not give me any errors before launching, but once the application has been launched, I get a terrible 'java.lang.UnsatisfiedLinkError: Native method not found: com.test.opencvcameratest.MainActivity.convertNativeGray(I)I' error for which there seems to be no logical reason as I'm fairly certain I've taken all the necessary steps to get to this point. 我的代码在启动之前没有给我任何错误,但是一旦启动了应用程序,我将得到一个可怕的'java.lang.UnsatisfiedLinkError: Native method not found: com.test.opencvcameratest.MainActivity.convertNativeGray(I)I'错误为此,似乎没有逻辑上的原因,因为我可以肯定地说,我已经采取了所有必要的步骤来达到这一点。 I've included my code below, and I'd be extremely grateful to anyone who can help me resolve this baffling mystery. 我在下面包含了我的代码,对于能帮助我解决这个令人困惑的谜团的人,我将深表感谢。

package com.test.opencvcameratest;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.WindowManager;

public class MainActivity extends Activity implements CvCameraViewListener2 { //implement    cvcameraviewlistener2 for camera functionality

private Mat mRgba;
private Mat mGray;

private CameraBridgeViewBase mOpenCvCameraView;

public native int convertNativeGray(int n);

private final static String TAG = "MainActivity";

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this)
{
    @Override
    public void onManagerConnected(int status)
    {
        switch(status)
        {
            case LoaderCallbackInterface.SUCCESS:
            {
                System.loadLibrary("OpenCVCameraTest");// Load Native module
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();

            }
        }
    }
};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_main);
    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);


}

@Override
public void onPause()
{
    super.onPause();
    if(mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
    Log.i("LOG MESSAGE", "OPENCV LOADED");
}

@Override
public void onDestroy()
{
    super.onDestroy();
    if(mOpenCvCameraView != null)
        mOpenCvCameraView.disableView();
}

@Override
public void onCameraViewStarted(int width, int height)
{
    //
}

@Override
public void onCameraViewStopped()
{
    //
}

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame)
{
    mRgba = inputFrame.rgba();
    //mGray = null;

    int i = convertNativeGray(5);

    return mRgba;
}

} }

This is the native .cpp file (OpenCVCameraTest.cpp). 这是本机.cpp文件(OpenCVCameraTest.cpp)。 It is clearly true that there DOES exist a convertNativeGray method, as opposed to what is being claimed by the linker. 与链接器所要求的相反,确实存在一个convertNativeGray方法。

#include <jni.h>
#include "opencv2/core/core.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>

using namespace cv;

extern "C"
{

JNIEXPORT jint JNICALL Java_com_test_opencvcameratest_convertNativeGray(JNIEnv*, jobject, jint n);

JNIEXPORT jint JNICALL Java_com_test_opencvcameratest_convertNativeGray(JNIEnv*, jobject, jint n)
{
    return n*2;
}

}

This is the Android.mk file. 这是Android.mk文件。

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on

LOCAL_SRC_FILES := OpenCVCameraTest.cpp

include C:\Users\user\Downloads\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk

LOCAL_LDLIBS +=  -llog -ldl
LOCAL_MODULE    := OpenCVCameraTest

include $(BUILD_SHARED_LIBRARY)

And I'll include the error cropping up too, for good measure. 我也将包括错误,以防万一。

03-31 16:57:47.627: E/AndroidRuntime(14335): FATAL EXCEPTION: Thread-33554
03-31 16:57:47.627: E/AndroidRuntime(14335): Process: com.test.opencvcameratest, PID: 14335
03-31 16:57:47.627: E/AndroidRuntime(14335): java.lang.UnsatisfiedLinkError: Native method not found: com.test.opencvcameratest.MainActivity.convertNativeGray:(I)I
03-31 16:57:47.627: E/AndroidRuntime(14335):    at com.test.opencvcameratest.MainActivity.convertNativeGray(Native Method)
03-31 16:57:47.627: E/AndroidRuntime(14335):    at com.test.opencvcameratest.MainActivity.onCameraFrame(MainActivity.java:101)
03-31 16:57:47.627: E/AndroidRuntime(14335):    at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
03-31 16:57:47.627: E/AndroidRuntime(14335):    at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:328)
03-31 16:57:47.627: E/AndroidRuntime(14335):    at java.lang.Thread.run(Thread.java:864)

本机功能应为

JNIEXPORT jint JNICALL Java_com_test_opencvcameratest_MainActivity_convertNativeGray() 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM