【问题标题】:Runtime error when run android app with ndk使用 ndk 运行 android 应用程序时出现运行时错误
【发布时间】:2014-11-27 22:19:57
【问题描述】:

我尝试使用 c++ 代码 (NDK) 运行我的 android 应用程序。制作了文件 libF.so。没有错误的应用程序运行但 得到“不幸的是已经停止”。我用过 try and 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){}

【问题讨论】:

    标签: android opencv android-ndk


    【解决方案1】:

    函数必须声明为

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

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

    您可以在您的 libF.so 上运行 nm -D,以了解 C++ 究竟是如何破坏您的 ma​​nic() 函数的名称的。

    【讨论】:

    • 问题没有解决,我从日志猫得到照片,URL = imageupload.co.uk/images/2014/10/03/log.png
    • 我的包名 = com.opencv.filter。 “主要”是名称类。以前在使用 c 编程在 android (native) 中同名。这里我使用C++编程
    • NDK 工具链 bin 目录中有 nm 可执行文件。在你的 libF.so 上用-D 试试。您将看到 C++ 如何修改 mainc 函数的名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2014-05-14
    • 2018-08-26
    • 1970-01-01
    相关资源
    最近更新 更多