The following settings works for me:
- Open file
Android.mk
(in folderjni
) and set path to fileOpenCV.mk
(from OpenCV for Android):
In my case it was:
C:\DP\OpenCV-2.4.8-android-
sdk\sdk\native\jni\OpenCV.mk
The whole Android.mk
will then look like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include C:\DP\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk
LOCAL_MODULE := native_sample
LOCAL_SRC_FILES := App_02_28.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
Add
System.loadLibrary("native_sample");
to methodonManagerConnected
in classMainActivity.class
; (bacause we use name"native_sample"
in first step in fileAndroid.mk
)
The whole onManagerConnected
will then look like this:
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
System.loadLibrary("native_sample");
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
- Right click on project and choose
Android tools -> Add native support
- Then set in
Properties -> C/C ++ General -> Paths and Symbols
on the cardIncludes
the following paths . In my case it was the following:
${NDKROOT}/platforms/android-9/arch-arm/usr/include
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include C:\DP\OpenCV-2.4.8-android-sdk\sdk\native\jni\include
jni
C:\DP\NDK\android-ndk-r9c\platforms\android-8\arch-arm\usr\include
C:\DP\NDK\android-ndk-r9c\sources\cxx-stl\gnu-libstdc++\4.6\include\backward
C:\DP\NDK\android-ndk-r9c\sources\android\native_app_glue
C:\DP\NDK\android-ndk-r9c\platforms\android-19\arch-arm\usr\include
C:\DP\NDK\android-ndk-r9c\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.6\include
C:\DP\NDK\android-ndk-r9c\toolchains\arm-linux-androideabi-4.6\prebuilt\windows\lib\gcc\arm-linux-androideabi\4.6\include-fixed
Of course, you must replace C:\DP\NDK\
by path where the Android NDK and OpenCV SDK is stored on your disk.
- Add to Properties -> C/C++ Build -> Environment the following variables:
... where the value of PATH
corresponds with what I have set the system PATH
.
- Finally,right clicking on your project and select
Index - Rebuild