Cocos2d-x on Android Studio - New CPP files are not listed

最后都变了- 提交于 2019-12-12 09:22:30

问题


Android Studio 2.3.3 (LATEST)

Cocos2d-x 3.15.1 (LATEST)

It's my first experience with Cocos2d-x Game Engine, I encountered a lot of problems. The first time I tried the latest NDK of Android Studio but there is a bug on this NDK version when I tried to compile my project with : cocos compile -p android --android-studio so I change the NDK version to 13b.

When I changed to NDK 13b the compilation was done without any problems and android studio build my project successfully but when I tried to create new CPP FILE or JAVA FILE or anything inside the Classes folder, Android Studio It does not display anything except the first CPP FILES, then I changed again NDK to 14b and I encountered the same problem.

The CPP files exist on my disc but Android Studio could not detect the files I created.

To avoid all these problems I think of migrating to eclipse, is a good choice ? I guess eclipse is better for performance and stability, please answer to this question, because I lost 3 days to test...ect

In fact I created several files inside Classes folder but look to the image :

Thank you,


回答1:


I found the solution, the solution is to using Wildcards eliminates and modify Android.mk each time you add a file inside Classes folder.

like this :

...
LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES_JNI_PREFIXED := \
    $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp) \
    $(wildcard $(LOCAL_PATH)/../../../Classes/**/*.cpp) \
    $(wildcard $(LOCAL_PATH)/../../../Classes/**/**/*.cpp)  

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   $(LOCAL_SRC_FILES_JNI_PREFIXED)
...

If you add a new cpp file, you need to update Android.mk

In addition, please run “Build > Refresh Linked C++ Projects” of Android Studio menu.




回答2:


If found another solution to add all files, without modifying Android.mk each time you add a file inside Classes folder.

    LOCAL_SRC_FILES := hellocpp/main.cpp

    FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp)
    LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)

    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

To add other cpp files from another folder you can use ( LOCAL_SRC_FILES += ) just change directory name according to yours.

    FILE_LIST := $(wildcard $(LOCAL_PATH)/../../../DirectoryName/*.cpp)
    LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)


来源:https://stackoverflow.com/questions/45725259/cocos2d-x-on-android-studio-new-cpp-files-are-not-listed

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