Search code examples
c++android-studioandroid-ndkcocos2d-xndk-build

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


Android Studio 2.3.3

Cocos2d-x 3.15.1

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.


Solution

  • 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.