使用ndk运行android app时出现运行时错误

时间:2014-10-02 20:26:59

标签: android opencv android-ndk

我尝试使用c ++代码(NDK)运行我的Android应用程序。文件libF.so已建成。 app没有错误运行但是 不幸的是,已经停止了#34;我使用过try和catch但没有使用消息。我甚至清除了C ++函数体。 我不知道该怎么办而且我不知道问题出在哪里。

我的英语不好,请原谅我

我的java代码是:

public class main extends Activity {
    /** Called when the activity is first created. */

    static{
        System.loadLibrary("F");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try{
            mainc();

        }catch (Exception e) {
            // TODO: handle exception
            Log.e("lee", e.getMessage());
        }
    }

    private static native void mainc();
}

c ++代码(F.cpp):

#include <jni.h>
#define JNIIMPORT
    #define JNIEXPORT  __attribute__ ((visibility ("default")))
#define JNICALL

using namespace std;
JNIEXPORT void JNICALL Java_com_opencv_filter_main_mainc(JNIEnv * jenv, jclass){}

1 个答案:

答案 0 :(得分:2)

该函数必须声明为

extern "C" JNIEXPORT void JNICALL Java_com_opencv_filter_main_mainc(JNIEnv * jenv, jclass);

如果这不能解决问题,请在尝试运行时添加有关您在logcat中看到的内容的更多信息。你的包裹实际上是 com.opencv.filter.main 吗?

您可以在 libF.so 上运行nm -D,以查找C ++是如何严格破坏狂躁()功能的名称。