UnsatisfiedLinkError: Native method not found - Android

余生颓废 提交于 2020-01-03 17:05:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!