user485498
user485498

Reputation:

OpenCV Android NDK Project will not build

I am using OpenCV 2.4.4 with Eclipse Juno on Ubuntu. My problem is similar to this one OpenCV for android sample programs showing error

But is now weirding me out. I spent most of my weekend trying to get the ndk and opencv library to play nice and still I cannot get it to work. I have in my test C++ cpp file with the following includes -

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cstdlib>

using namespace cv; //this is a problem
...
...

And it tells me when I try to build that "namespace cv cannot be found". Oh well, I must have written some path wrong or am not using the correct library, right? Wrong. In the terminal, ndk-build builds the .so files without any errors. I can see them plain as day in the project folder. But if I try to do build in eclipse, i.e. build the apk for tesitng on a virtual device or real device, then I get the namespace cv error and the build fails and then in the cpp file cv is underlined red and in eclipse the file is marked red and I can't even attempt to build until this file is "corrected".

Clearly I'm doing something wrong. But if I close my eclipse project and then reopen it, the cpp file is no longer marked red and I can make an apk build. If I attempt to open the cpp file the red returns and no more builds can happen until I go through the project close/open rigmarole.

I honestly don't know what the cause of the problem is. Any help would be greatly appreciated.

My android.mk file:

include $(CLEAR_VARS)


OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=STATIC
include /the/correct/path/tp/opencv/sdk/native/jni/OpenCV.mk 

LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := mylib.cpp
include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all #i have tried various targets
APP_PLATFORM := android-8
APP_MODULES := mylib

I didn't think it would be this difficult. I should add that I have successfully used opencv with Android in anothe rproject I built on WIndows with Eclipse 3.5 (I think) and OpenCV 2.4.2

EDIT I also want to say that I just did a quick 'n dirty test opencv operation. I wrote a quick Sobel function and called it as a native function in a Java file and "sobelled" a bitmap successfully. Of course, I still had to close/open my project to do this.

Upvotes: 4

Views: 2930

Answers (2)

Julio
Julio

Reputation: 27

I know that's maybe too late, but in my case (Windows+Eclipse) I correct this problem just changing the backslash "\" to slash "/" in the Path and Symbols include of opencv jni libs.

Example: Wrong H:\opencv\sdk\native\jni\include Correct H:/opencv/sdk/native/jni/include

Upvotes: 0

Dururu
Dururu

Reputation: 11

Hi I had same problem with you and after I added below "opencv android sdk" path that include problem disappeared.

exp : C:\project\OpenCV-2.4.6-android-sdk\sdk\native\jni\include switch the path with your opencv-android-sdk path.

Upvotes: 1

Related Questions