Search code examples
androidjsonandroid-ndkcocos2d-xandroid.mk

Error in compiling cocos2d-x project for android when using json


I'am using cocos2d-x version 3.3rc In some of my class I #include "cocos2d/external/json/writer.h" when I want to compile my project to make android apk, by running build_native.py script, it shows the following error to me:

fatal error: cocos2d/external/json/writer.h: No such file or directory

But I include its file in my android.mk file with this syntax:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
                    $(LOCAL_PATH)/../../cocos2d/external/json \

And here is the complete android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)


LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
                    ../../Classes/AppDelegate.cpp \
                    ../../Classes/Database/CacheData.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
                    $(LOCAL_PATH)/../../cocos2d/external/json 

#LOCAL_STATIC_LIBRARIES := cocos2dx_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
LOCAL_WHOLE_STATIC_LIBRARIES += json_external_static


include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)

How can I fix the problem?


Solution

  • I found the solution. In cocos2d-x version 3.3 the default android.mk file that generated is sufficient and all other library was imported. Then the default android.mk file in jni folder was completely integrated with other .mk files. i see that the files in json folder that located in 'cocos2s/external/json' are .h files and there is no dependency between them and other cocos2d files and library. then I simply copy this folder to my Classes folder and include them locally.Now the problem is solved :)