[英]java.lang.UnsatisfiedLinkError: Native method not found in Android
Could someone help me locate my error, I have looked at looked I can't seem to find it, I am trying to run my code but it keeps giving me the error java.lang.UnsatisfiedLinkError: Native method not found: nemo.lungu.receiptor.scanlibrary.ScanActivity.getPoints:(Landroid/graphics/Bitmap;)[F
below is my activity method getPoints()
: 有人可以帮助我定位我的错误,我看了看似乎找不到,我正在尝试运行我的代码,但它一直给我错误
java.lang.UnsatisfiedLinkError: Native method not found: nemo.lungu.receiptor.scanlibrary.ScanActivity.getPoints:(Landroid/graphics/Bitmap;)[F
下面是我的活动方法getPoints()
:
public native float[] getPoints(Bitmap bitmap);
the Header version of the method getPoints()
: 方法
getPoints()
的标头版本:
JNIEXPORT jfloatArray JNICALL Java_nemo_lungu_receiptor_scanlibrary_ScanActivity_getPoints
(JNIEnv *, jobject, jobject);
and finally the implementation of the method getPoints()
in my .cpp
file: 最后在我的
.cpp
文件中实现getPoints()
方法:
JNIEXPORT jfloatArray JNICALL Java_nemo_lungu_receiptor_scanlibrary_ScanActivity_getPoints
(JNIEnv *env, jobject thiz,jobject bitmap)
{
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Scaning getPoints");
int ret;
AndroidBitmapInfo info;
void* pixels = 0;
if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME,"AndroidBitmap_getInfo() failed ! error=%d", ret);
return 0;
}
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888 )
{ __android_log_print(ANDROID_LOG_VERBOSE, APPNAME,"Bitmap format is not RGBA_8888!");
return 0;
}
if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME,"AndroidBitmap_lockPixels() failed ! error=%d", ret);
}
// init our output image
Mat mbgra(info.height, info.width, CV_8UC4, pixels);
vector<Point> img_pts = getPoints(mbgra);
jfloatArray jArray = env->NewFloatArray(8);
if (jArray != NULL)
{
jfloat *ptr = env->GetFloatArrayElements(jArray, NULL);
for (int i=0,j=i+4; j<8; i++,j++)
{
ptr[i] = img_pts[i].x;
ptr[j] = img_pts[i].y;
}
env->ReleaseFloatArrayElements(jArray, ptr, NULL);
}
AndroidBitmap_unlockPixels(env, bitmap);
return jArray;
} }
Am loading the library like: 正在加载库,如下所示:
static {
System.loadLibrary("myLibraryName");
}
Which seems to load successfully as it gives me the message Added shared lib /data/app-lib/nemo.lungu.receiptor-2/myLibraryName.so 0xa4fe5e78
but again after that it gives me another message to say No JNI_OnLoad found in /data/app-lib/nemo.lungu.receiptor-2/myLibraryName.so 0xa4fe5e78, skipping init
so I do not know if that is the cause or something else. 这似乎已成功加载,因为它给了我以下消息:
Added shared lib /data/app-lib/nemo.lungu.receiptor-2/myLibraryName.so 0xa4fe5e78
但在此之后再次给了我另一条消息,说No JNI_OnLoad found in /data/app-lib/nemo.lungu.receiptor-2/myLibraryName.so 0xa4fe5e78, skipping init
所以我不知道这是原因还是其他原因。
我需要将extern "C"
放在我的getPoints()
前面,因为JNI
无法理解C++
命名转换,因此我的.cpp
文件中的getPoints()
方法需要看起来像extern C JNIEXPORT jfloatArray JNICALL Java_nemo_lungu_receiptor_scanlibrary_ScanActivity_getPoints (JNIEnv *env, jobject thiz,jobject bitmap) {//method implementation}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.