找不到不满意的linkerror本机方法

时间:2014-12-04 12:40:59

标签: android c++ opencv java-native-interface runtime-error

现在我收到了错误:

unsatisfiedLinkerror native method not found.2-04 07:16:34.002: E/AndroidRuntime(1962): java.lang.UnsatisfiedLinkError: Native method not found: com.example.hellocplusplus.MainActivity.camera:()I.

请帮帮我

我的c ++代码:

#include <opencv/cv.h>



#include <jni.h>




#include <opencv/highgui.h>





using namespace cv;



/************************************************************************************************************
**
***********************************************************************************************************/



extern "C"{

JNIEXPORT jint JNICALL Java_com_example_hellocplusplus_MainActivity_camera
  (JNIEnv *, jobject);


JNIEXPORT jint JNICALL Java_com_example_hellocplusplus_MainActivity_camera
  (JNIEnv *, jobject)
{

            VideoCapture cap(0); // open the video camera no. 0

            if (!cap.isOpened())  // if not success, exit program
            {
                //cout << "Cannot open the video cam" << endl;
                return -1;
            }

            namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a windowcalled "MyVideo"

            //Show continous video on the output window
            while (1)
            {
                Mat frame;

                bool bSuccess = cap.read(frame); // read a new frame from video

                if (!bSuccess) //if not success, break loop
                {
                    //cout << "Cannot read a frame from video stream" << endl;
                    break;
                }

                imshow("MyVideo", frame); //show the frame in "MyVideo" window

                if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
                {
                    //cout << "esc key is pressed by user" << endl;
                    break;
                }
            }

            return (jint) 0;
        }

}

我的java代码:

package com.example.hellocplusplus;

import org.opencv.android.BaseLoaderCallback;

import org.opencv.android.LoaderCallbackInterface;



import org.opencv.android.OpenCVLoader;



import android.os.Bundle;




import android.app.Activity;




import android.util.Log;




import android.view.Menu;

public class MainActivity extends Activity {

    public static String TAG="OpenCVImageProcessing";
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    System.loadLibrary("nativegray");
                    Log.i(TAG, "OpenCV loaded successfully");

                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };
    public native int camera();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     camera();
        //i=camera();
        //System.out.println(i);
      //  camera1();
    }
    public void onResume()
    {
        super.onResume();
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
    }







    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

1 个答案:

答案 0 :(得分:0)

基本上,当你调用camera()代码时,你的“nativegray”没有加载。

你不能在onCreate()中调用任何opencv代码,因为一旦mLoaderCallback完成,opencv so(以及你自己的)也只会被加载,从onResume()

调用

然后,你的c ++代码永远不会工作。

你不能在android(E_NOKEYBOARD)上调用namedWindow(),imshow()或waitKey(), 和while(1)循环不合法,因为它会阻止你的活动。