I am having problems with the Eclipse indexer for my NDK project. There's a lot of similar threads out there but none that seem to touch on the same source of problems. I have an OpenGL ES application that I need to port over to Android written purely in C that I'd like to run as a NativeActivity, preferably having no Java attached to it. The code compiles fine using ndk-build
after a lot of rewriting, but from the IDE there's a lot of errors such as Type 'GLfloat' could not be resolved
. An APK gets produced and I can install it with adb
and all, but I want to be able to use the IDE, especially for debugging.
If I choose 'Open Declaration' in the context menu for a line such as #include <GLES2/gl2.h>
then Eclipse is able to display the file and I see the GLfloat
definition is there but I get no info while hovering over anything in that file so I guess the indexer just skips it somehow? Header files not in the Android NDK directory get indexed just fine, such as those in the jni
folder and subfolders like jni/png
. I have NDKROOT
root defined under C/C++ Build -> Environment
, a project with native capabilities and using the CDT view.
One thing I noticed was that when I set up the project initially I had a .cpp
file which the indexer had no problem providing Android NDK information for, but as soon as I changed it to .c
the errors started appearing. I am under the impression that the Android NDK is made for use with C with only basic C++ support but looking around in the samples and such I just see a bunch of .cpp
files so I am confused. I've tried setting LOCAL_CPP_EXTENSION += .c
in my Android.mk
but that caused Eclipse to hang during build. The last thing I haven't tried is renaming all the files so they get compiled with a C++ compiler instead but I don't see why this should be necessary and I have some third-party libraries like zlib included by source that I'd rather not fiddle with.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
define all-cpp-files-under
$(patsubst ./%, %, \
$(shell cd $(LOCAL_PATH) ; \
find $(1) -name "*.c" -and -not -name ".*") \
)
endef
LOCAL_MODULE := MyProject
LOCAL_SRC_FILES := $(call all-cpp-files-under, .)
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -lOpenSLES
LOCAL_STATIC_LIBRARIES := android_native_app_glue
LOCAL_C_INCLUDES += $(LOCAL_PATH)/jansson
LOCAL_C_INCLUDES += $(LOCAL_PATH)/zlib
LOCAL_C_INCLUDES += $(LOCAL_PATH)/png
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Application.mk
APP_PLATFORM := android-9
APP_ABI := all