1

I have all the prebuilt Open CV .so files in the jniLibs directory while I have some C++ files which use the OpenCV as well.I have the following Android.mk and Application.mk scripts .

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= opencv-prebuilt
LOCAL_SRC_FILES:= ../jniLibs/$(TARGET_ARCH_ABI)/libopencv_java.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/build/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE     := AN
LOCAL_SRC_FILES  := A.cpp B.cpp
LOCAL_SHARED_LIBRARIES := opencv-prebuilt
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8

Why does it keep giving me error no such directory or file found and points to #include <opencv2/opencv.hpp> statement in my jni directory when I try to compile?

I have looked at another similar question here but I was unable to solve it via the solution

Community
  • 1
  • 1
  • You need to add the path to the .hpp in your LOCAL_INCLUDES, otherwise it doesn't know where to find it. Of course there's supposed to be issues with radle and the NDK, so good luck. – Gabe Sechan Apr 15 '15 at 22:51

1 Answers1

2

You should only include header files strictly required by certain source i.e.

#include <DetectionBasedTracker.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/detection_based_tracker.hpp>

Considering the accepted answer you're referencing as a possible solution for your issue as a reference the directory where you should put SO files are set up on app/build.grade:

sourceSets.main {
    jniLibs.srcDir 'src/main/libs' //set .so files location to libs
    jni.srcDirs = [] //Disable automatic ndk-build call
}

tasks.withType(NdkCompile) {
    compileTask -> compileTask.enabled = false
}

Nevertheless I'd still try to reference OpenCV.mk in your Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
include /Users/egomez/dev/OpenCV4AndroidWorkspace/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk

Hope it helps.

Eduardo Gomez
  • 425
  • 3
  • 12
  • I am getting an error saying `Error:(23, 0) Could not find property 'NdkCompile' on com.android.build.gradle.AppExtension_Decorated@a550b6.` – Romantic Electron Apr 16 '15 at 07:34
  • Thanks , I was able to run the app after inclusion of `com.android.build.gradle.tasks.NdkCompile;`in my com.android.build.gradle.tasks.NdkCompile; – Romantic Electron Apr 16 '15 at 10:37
  • 1
    @RomanticElectron could you expand on the fix? Where did you add the above modification? – JParrish88 Dec 14 '15 at 09:13
  • 1
    @JParrish88 use import at beginning of the same gradle build file like this: import com.android.build.gradle.tasks.NdkCompile; – Numenor Feb 19 '16 at 09:58