0

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

2 Answers2

1

This may is not be the right way to fix the problem, but you can find the file ${WORKSPACE_LOC}/.metadata/.plugins/com.android.ide.eclipse.ndk/${ProjName}.pathinfo. It is a text file, in simple format. To begin with, try to delete this file, and rebuild the project. If this does not help, you can add

i,d:/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/include
i,d:/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/include-fixed
i,D:/Android/android-ndk-r9/platforms/android-14/arch-arm/usr/include

manually (the example above is for Windows).

Update a better workaround is to set up ADT to work with indexer correctly, see Android NDK build, Method could not be resolved or Eclipse compiles successfully but still gives semantic errors.

Community
  • 1
  • 1
Alex Cohn
  • 52,705
  • 8
  • 94
  • 269
  • I tried removing it but the file that got rebuilt looks exactly the same. The file already contains those include paths at the top, the head of the file looks like this: http://pastebin.com/pUvJbjxK – Rickard Westerlund Oct 15 '13 at 07:26
  • In your Eclipse, do you see **GLfloat** green, or underlined in red? If it is not green, try to comment out ALL of the C file, and add two lines at the top: `#include ` and `GLfloat qqq;` is it green now? – Alex Cohn Oct 15 '13 at 09:35
  • No, with just those two lines the `GLfloat` is still red. I did try renaming all `.c` files in the base `jni` folder to `.cpp` and this on the other hand turns the `GLfloat` and when I hover it it will say that it's a typedef of `khronos_float_t`. The issue seems to be that the IDE interprets the Android NDK headers as C++ includes but I have no idea how to fix that. – Rickard Westerlund Oct 15 '13 at 09:45
  • In your Eclipse project *Properties*, what does `C/C++ General` -> `Paths and Symbols` show when you turn *Show built-in values* off? on? – Alex Cohn Oct 15 '13 at 09:57
  • Turning it off makes all entries disappear, they're all built-ins. There's also just one language of `c,cpp` in the list and neither the built-in includes nor the language can be modified. – Rickard Westerlund Oct 15 '13 at 10:01
  • Sorry, this all looks as if it should work. There is always a chance that reinstalling ADT may help, and/or starting with new clean workspace. But that's on the voodoo side of sw development :-( – Alex Cohn Oct 15 '13 at 10:31
  • I can't think of anything myself either without getting any diagnostics from Eclipse. I could add this is on a Mac and I haven't tried working with a Windows or Linux environment but it feels like it shouldn't matter. My ADT and NDK installation was pretty fresh from a week ago but I could try that. Thanks for all the help, I suppose I'll stick to converting everything for C++ compilation. – Rickard Westerlund Oct 15 '13 at 18:02
  • 1
    I should add that I did a clean installation of the Android SDK & NDK and now I am also able to debug using `ndk-gdb`. I haven't checked if I can use .c files but at this point it doesn't matter since I already rewrote everything, so I am able to get things done now. – Rickard Westerlund Oct 23 '13 at 12:22
1

right click on the jni folder and got to property click on c/c++ general and in include folder include below files exists in your ndk please import and must click apply

d:/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/include
i,d:/android/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.6/include-fixed
i,D:/Android/android-ndk-r9/platforms/android-14/arch-arm/usr/include
sharma_kunal
  • 2,018
  • 1
  • 26
  • 27