gpt4 book ai didi

java.lang.UnsatisfiedLinkError : Native method not found in Android 错误

转载 作者:行者123 更新时间:2023-11-28 02:07:55 26 4
gpt4 key购买 nike

谁能帮我找到我的错误,我看了看我似乎找不到它,我正在尝试运行我的代码但它一直给我错误 java.lang.UnsatisfiedLinkError: Native method未找到:nemo.lungu.receiptor.scanlibrary.ScanActivity.getPoints:(Landroid/graphics/Bitmap;)[F 下面是我的 Activity 方法getPoints():

   public native float[] getPoints(Bitmap bitmap); 

getPoints() 方法的 Header 版本:

JNIEXPORT jfloatArray JNICALL  Java_nemo_lungu_receiptor_scanlibrary_ScanActivity_getPoints
(JNIEnv *, jobject, jobject);

最后是我的 .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;

正在像这样加载库:

  static {

System.loadLibrary("myLibraryName");
}

这似乎加载成功,因为它给我消息 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 位图)
{//方法实现

关于java.lang.UnsatisfiedLinkError : Native method not found in Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36781353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com