unity plugin with android run error with include libopencv_java.so

asked 2013-09-16 04:22:48 -0500

hardy_bbs gravatar image

I made a very simple native plugin, it run ok without include a opencv header. if I include a opencv header with include libopencv_java.so. I still can bulid .so file with NDK. but when run at android device it seam fail to execute add function. only ouput "here1". I got a error on logcat with fail load LibHardy.so ,but I also can run opencv example good except can not run on unity. means opencv has invoke this .mk successfull, it seams unity runtime can not work with libopencv_java.so , do you have any suggestion ? Thanks and best wish.

Android.mk

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := $(OPENCV_INCLUDE_DIR)
LOCAL_EXPORT_C_INCLUDES := $(OPENCV_INCLUDE_DIR)
LOCAL_CFLAGS     += -fPIC -DANDROID -fsigned-char

LOCAL_MODULE := opencv_core
LOCAL_SRC_FILES := $(OPENCV_LIBS_DIR)/libopencv_java.so 
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_SHARED_LIBRARIES := opencv_core  
LOCAL_C_INCLUDES := $(OPENCV_INCLUDE_DIR)
LOCAL_ARM_MODE  := arm
LOCAL_MODULE    = libHardy
LOCAL_SRC_FILES += NativeCode.cpp
#LOCAL_LDLIBS   += -lm -llog  
LOCAL_CFLAGS    += -Werror
include $(BUILD_SHARED_LIBRARY)

NaticeCode.CPP

#include <string.h>
#include <jni.h>
#include <android/log.h>

extern "C" {
float add(float x, float y)
{
    // LOGI("add extern C \n");
    // callTest();
    return x + y + 12;
}
}

UnityCall.cs

[DllImport("Hardy")]
private static extern float add(float x, float y);

bool found = true;
String msg="null:";
void Start ()
{
    msg = "here1";
    msg = "here1"+add (23,23); //failed here and jump out start , it did't go to next
    startCam();
    msg = "here2";
    texture = new Texture2D(256, 256, TextureFormat.RGBA32, false);
    msg = "here3";
    cubeObj.renderer.material.mainTexture = texture;
    msg = "here4";
}
edit retag flag offensive close merge delete