Eclipse ADT “… could not be resolved” with Android NDK and C files

我的梦境 提交于 2019-12-02 22:01:35

问题


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

回答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.




回答2:


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


来源:https://stackoverflow.com/questions/19360668/eclipse-adt-could-not-be-resolved-with-android-ndk-and-c-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!