问题
I am developing an android app using C++ code. Trying to use JNI but failed. The code in myFirstApp.cpp
JNIEXPORT jint JNICALL Java_com_example_myfirstapp_CreateApp_findMarkersNative(
JNIEnv* env, jobject, jlong addrRgba) {
//clock_t begin = clock();
Mat& mRgb = *(Mat*) addrRgba;
Mat mgray(mRgb.rows, mRgb.cols, CV_8UC1);
cvtColor(mRgb, mgray, CV_RGBA2GRAY, 1); // the working one
clearVectors();
findSquares(mgray);
mergeRectangles();
processFilteredSquares(mgray);
drawFilteredSquaresWithoutMarker(mRgb);
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Candidates %i",candidates.size());
return clusterBoundaries.size();
// clock_t end = clock();
// mgray.release();
}
In the android activity(CreateApp), I've declared the method
public native int findMarkersNative(long imgAdd);
The package name in the activity is
package com.example.myfirstapp;
The error appearing the logcat
Caused by: java.lang.UnsatisfiedLinkError: Native method not found com.example.myfirstapp.CreateApp.findMarkersNative
回答1:
Your definitions seem correct. According to several similar posts, it may be because of C / C++ name mangling. Try surrounding your methods, around where this API is defined with
extern "C" { }
for example:
extern "C" {
JNIEXPORT jint JNICALL Java_com_example_myfirstapp_CreateApp_findMarkersNative(JNIEnv* env, jobject, jlong addrRgba)
{
... function code ...
}
}
Source: Unsatisfied link error
来源:https://stackoverflow.com/questions/16409425/unsatisfiedlinkerror-native-method-not-found-android