[android] the build fails if the file that existed during the previous compilation no longer exists

[android] the build fails if the file that existed during the previous compilation no longer exists
0

When building with Android, the build fails if the file that existed during the previous compilation no longer exists.

For example, it consists of the following in the first build.

Hello.cpp
Hello.h
Main.cpp
Main.h

And when I try to do the second build, it consists of the following.

Main.cpp
Main.h

The build fails in this or similar cases.
Sometimes the build fails even when new files are added.

If I delete the proj.android/app/.externalNativeBuild folder and compile it works fine.

This is the error content.

Build command failed.
Error while executing process C:\Cocos\AndroidSDK\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Cocos\Projects\BGMaker\proj.android\app\.externalNativeBuild\cmake\debug\arm64-v8a --target MyGame}
ninja: error: '../../../../../../Classes/MButton_.cpp', needed by 'CMakeFiles/MyGame.dir/Classes/MButton_.cpp.o', missing and no known rule to make it

Is there any problem in automating CMakeList.txt as below?

file (GLOB_RECURSE MY_SOURCES Classes/*.cpp
Classes/filters/nodes/*.cpp)
file (GLOB_RECURSE MY_HEADERS Classes/*.h)

list(APPEND GAME_SOURCE ${MY_SOURCES})
list(APPEND GAME_SOURCE ${MY_HEADERS})

If you’re using Android Studio, it should automatically pick up the changes in the CMakeLists.txt, and re-syncs the project by calling CMake again, which re-builds the cached files. Is it not doing that, or are you not using Android Studio?

thank you for answering!
I’m using android studio.
I just removed some source files from the project and built it, but it didn’t re-sync automatically.

Sorry, I didn’t notice that you are using GLOB_RECURSE. That is the source of your problem, and if you want to know why, this post has some good info: https://stackoverflow.com/questions/32411963/why-is-cmake-file-glob-evil

I understand why it is a problem.
However in the question you linked to, the questioner says that you can do ‘touch CMakeLists.txt’. What is this?
I am using windows and tried typing in cmd but nothing happened.
Thank you!!

The most obvious solution is to not use GLOB_RECURSE, and it is very little effort to explicitly list all the source files in the CMakeLists.txt.

Now, regarding the touch command, Linux has it, but no direct equivalent exists on Windows. A web search for something similar on Windows would have given you a result like this: https://superuser.com/questions/10426/windows-equivalent-of-the-linux-command-touch/764716

aha touch command is just updating the timestamp to the current time.
Then, when I add or remove the source file, save the cmakefile again!

thank you!!

You may check: https://cmake.org/cmake/help/latest/command/file.html

Option:
CONFIGURE_DEPENDS

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.