无法解析对应的jni函数opencv Android [英] Cannot resolve corresponding jni function opencv Android

查看:114
本文介绍了无法解析对应的jni函数opencv Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我得到错误的地方.我正确加载了opencv库,但出现了此错误.如果我进入ximgproc,则所有本机方法都用红色标记为无法解析相应的jni函数name_function".我该如何解决? >

this is where i get error.I loaded correctly opencv library but i get this error.If i go in the ximgproc all native methods are red marked with "Cannot resolve corresponding jni function name_function".How can i resolve?

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {

        Uri uri = data.getData();
        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
            //Log.i("prova",uri.toString());
            ImageView imageView = (ImageView) findViewById(R.id.imageView);
           // imageView.setImageBitmap(bitmap);
            Mat g=new Mat(bitmap.getHeight(),bitmap.getWidth(), CvType.CV_8UC1);
            Utils.bitmapToMat(bitmap,g,true);
            SuperpixelSLIC x=Ximgproc.createSuperpixelSLIC(g,Ximgproc.SLIC,100,3);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

这是我得到的错误:

06-07 19:24:01.370 21090-21090/com.example.jt1995.provaemo E/art: No implementation found for long org.opencv.ximgproc.Ximgproc.createSuperpixelSLIC_0(long, int, int, float) (tried Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10 and Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10__JIIF)
06-07 19:24:01.370 21090-21090/com.example.jt1995.provaemo E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.jt1995.provaemo, PID: 21090
                                                                             java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.ximgproc.Ximgproc.createSuperpixelSLIC_0(long, int, int, float) (tried Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10 and Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10__JIIF)
                                                                                 at org.opencv.ximgproc.Ximgproc.createSuperpixelSLIC_0(Native Method)
                                                                                 at org.opencv.ximgproc.Ximgproc.createSuperpixelSLIC(Ximgproc.java:452)
                                                                                 at com.example.jt1995.provaemo.MainActivity.onActivityResult(MainActivity.java:108)
                                                                                 at android.app.Activity.dispatchActivityResult(Activity.java:6303)
                                                                                 at android.app.ActivityThread.deliverResults(ActivityThread.java:3818)
                                                                                 at android.app.ActivityThread.handleSendResult(ActivityThread.java:3865)
                                                                                 at android.app.ActivityThread.access$1700(ActivityThread.java:159)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5569)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)

推荐答案

正如我解释的

As I explained elsewhere, don't expect Android Studio to resolve magically the native method declarations into a library that is not built with gradle in integrated externalNativeBuild.

您可以简单地忽略此错误消息:即使Android Studio将其标记为红色,您的APK仍将安装预构建的库,并且本机方法将在运行时解析.

You can simply ignore this error message: your APK will still install the prebuilt library, and the native methods will be resolved at run time, even if Android Studio marks them red.

您可以为此方法或整个类添加@SuppressWarnings("JniMissingFunction")批注:

You can add @SuppressWarnings("JniMissingFunction") annotation for this method, or for the entire class:

@SuppressWarnings("JniMissingFunction")
public class Ximgproc {

或为给定项目或所有项目配置这种Lint检查:

or configure this kind of Lint inspections for the given project, or for all projects:

但是,这不能解决您的运行时问题.您大概已经构建了C ++代码来生成本地共享库,说它的名字是 libXimgproc-native.so .如果将它正确打包到您的APK中,它将被提取到/data/app-lib/com.example.jt1995.provaemo/(您可以使用getContext().getApplicationInfo().nativeLibraryDir检查此路径).

But this does not resolve your runtime problem. You presumably have built your C++ code to produce a native shared library, say its name is libXimgproc-native.so. If it is packed correctly into your APK, it will be extracted to /data/app-lib/com.example.jt1995.provaemo/ (you can check this path with getContext().getApplicationInfo().nativeLibraryDir).

您的Java代码应在尝试调用 org.opencv.ximgproc.Ximgproc 类的本机方法之前加载此库:

Your Java code should load this library before it tries to call the native methods of the org.opencv.ximgproc.Ximgproc class:

System.load("Ximgproc-native");

如果以上所有假设均正确,则链接器在该库中找不到实现 createSuperpixelSLIC_0 本机方法的导出函数.它同时尝试了Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10__JIIF.

If all above assumptions are correct, the linker did not find an exported function in that library that implements the createSuperpixelSLIC_0 native method. It tried both Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10 and Java_org_opencv_ximgproc_Ximgproc_createSuperpixelSLIC_10__JIIF.

要检查库导出了哪些方法,可以使用NDK gcc工具链中的 nm 工具.例如.在我的Mac上,该可执行文件可以在~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-nm处找到.

To check which methods are exported by the library, you can use the nm tool which is part of the NDK gcc toolchain. E.g. on my Mac this executable can be found at ~/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-nm.

运行…nm -D Ximgproc-native.so,它将用 T 列出库的所有导出功能.

Run …nm -D Ximgproc-native.so and it will list, with T, all exported functions of your library.

我相信您不会在此列表中找到您的功能.也许,这个名字有点不对.也许您将CFLAGS设置为 -fvisibility = hidden ,而没有将函数明确声明为JNIEXPORT(或__attribute__ ((visibility ("default")))).也许C ++函数未使用extern "C"声明,并且其名称由编译器修改.

I believe you will not find your function in this list. Maybe, the name is slightly wrong. Maybe, you set CFLAGS to -fvisibility=hidden, and did not explicitly declare the function as JNIEXPORT (or __attribute__ ((visibility ("default")))). Maybe, the C++ function is not declared with extern "C", and its name is mangled by the compiler.

如果使用静态库( xxx.a )作为组装结果共享库的中介,则应该知道链接器可以丢弃未使用的外部函数.在这种情况下,使用LOCAL_WHOLE_STATIC_LIBRARIES代替LOCAL_STATIC_LIBRARIES可能会有所帮助.

If you use static libraries (xxx.a) as intermediates to assemble the resulting shared library, you should know that the linker can throw away unused external functions. In such case, using LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES may help.

这篇关于无法解析对应的jni函数opencv Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆