Question

i have an android application with opencv library for the image processing. Also, i have a cpp file under my 'jni' folder. it worked very well before i change this cpp file. Then, the changes are not reflected in the build. How can i build my cpp file? However, i tried something as following;

  1. Eclipse->Window->preferences->Android->NDK And i browsed ndk location path.

  2. Go to my project->preferences-> ADD NATIVE SUPPORT then i clicked the finish button.

  3. After, i could see C/C++ build in the project preferences.

  4. Under the C/C++ build->Chain Tool Editor tab, i selected the G C Compiler and G C++ Compiler.

  5. C/C++ General-> Path and Symbols, i added the C:\Users\casper\Desktop\OpenCV-2.3.1\include to the path and symbols.

  6. C/C++ General->Preprocessor Include Paths..-> i checked the CDT GCC Built in Compiler Settings checkbox.

After that i run my application but i have some troubles. In my cpp files, unresolves inclusion for include tags.

for eg. Symbol 'cv' could not be resolved

i dont know what i must do rebuild the cpp files/jni. Or i have to do some changes in code on a different platform eg:visual c++, QT. And my last question is a QT an alternative to Android NDK (for dealing with jni, i mean if i wrote the code on QT then can QT build these code for the jni.)

No correct solution

OTHER TIPS

The following settings works for me:

  • Open file Android.mk (in folder jni) and set path to file OpenCV.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 method  

    onManagerConnected in class MainActivity.class; (bacause we use name "native_sample" in first step in file Android.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 card Includes 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:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top