Tuesday, August 25, 2015

Android NDK C++ Code Error Checking Trouble with Eclipse

Eclipse for Android NDK is mostly a user friendly environment.  But sometimes I encounter error checkng problem with c++ code.  While compile/build goes smoothly, every time I open a c++ file, many syntax error show up, and I got 100+ error messages under problem tab.  Under this circumstance, I cannot build the project before the error-flagging file is closed, and the error messages are manually deleted.  The build process goes smoothly: there is no error to begin with.

This brings a lot of inconvenience to coding.  On the other hand, some of my projects do not have this problem.  After some experimenting, I finally figure out why:  the include path list for syntax is not updated after first build.  One way to solve this problem is get Android.mk and Application.mk ready before the first build.  Here are my example, OpenCV is used in this project:


Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_SDK_JNI = C:\\OpenCV-2.4.10-android-sdk\\sdk\\native\\jni
include $(OPENCV_SDK_JNI)/OpenCV.mk
LOCAL_MODULE    := hello
LOCAL_SRC_FILES := hello.cpp
LOCAL_C_INCLUDES += $(OPENCV_SDK_JNI)/include
include $(BUILD_SHARED_LIBRARY)

Application.mk:

APP_ABI := armeabi-v7a
NDK_TOOLCHAIN_VERSION := 4.9
APP_CPPFLAGS += -std=c++11 -fexceptions  -frtti
APP_STL := gnustl_static

After this, I built the project for first time, this list of include folders will keep Eclipse from falsely flag error is c++ source code.