Cannot resolve corresponding jni function opencv Android

前端 未结 1 1702
清酒与你
清酒与你 2020-12-20 03:40

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 correspondin

相关标签:
1条回答
  • 2020-12-20 03:56

    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.

    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.

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

    @SuppressWarnings("JniMissingFunction")
    public class Ximgproc {
    

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

    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).

    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");
    

    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.

    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.

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题