我正在使用OpenCV开发一个Android项目.有些方法没有Java版本,所以我必须使用NDK在我的项目中使用它们.
这是我第一次使用NDK,所以在搜索了一些例子之后,我编写了我的代码,在我的设备上运行它,并收到以下错误消息:
07-04 10:26:19.555 21270-21270/com.example.MyTest E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Native method not found: com.example.MyTest.JNIlib.readImg:()I
at com.example.MyTest.JNIlib.readImg(Native Method)
at com.example.MyTest.MyActivity$2.onClick(MyActivity.java:60)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我多次重新生成.so文件,并检查jni函数的命名.我还为jni函数添加了'extern"C"'包装器.但这些解决方案都没有奏效.
注意:我总是使用Intellij Idea来开发JAVA程序,因为Idea不支持NDK,我必须使用Eclipse来访问NDK,所以...这也是我第一次使用Eclipse.我本可以犯很多愚蠢的错误.大声笑
下面是我的c ++代码和makefile.
LocalMain.cpp
#include <stdio.h>
#include <iostream>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/opencv.hpp>
#include <jni.h>
#include <android/log.h>
#include "LocalFeature.h"
using namespace cv;
using namespace std;
int readImg()
{
/* do something*/ …Run Code Online (Sandbox Code Playgroud)