Can't compile Android after adding new classes

I got the Android sample compiling (in Android Studio), but when I removed HelloWorldScene etc. and added in my own classes e.g. MainMenuScene, the project wouldn’t compile, the compiler complains:

…/…/…/…/…/…/Classes/AppDelegate.cpp:127: error: undefined reference to ‘MainMenuScene::createScene()’

So it seems the project isn’t picking up those new classes. I did have to edit CMakeLists.txt to remove references to HelloWorldScene, do I need to some additions to build files for new classes to get picked up? Do I have to manually add them to the project? I notice the “classes” folder in the project is empty, but it was before too. Something’s missing here, not sure what…

The compiler error is showing you exactly what the problem is.

If you removed HelloWorldScene.cpp/.h from CMakeLists.txt, then wouldn’t you think it’s a good idea to add MainMenuScene.cpp/.h to it now that you’re using those files?

Everything needs to go through CMake. Any new source files you want to add need to be listed in the CMaleLists.txt file (or files, depending on how you structure you project). Do not add anything directly into the Android Studio project.

If you’re not sure what to do, then perhaps learning about CMake is a good place to start.

1 Like

Stupid question I guess… I did add the files, but it didn’t take effect until I did a couple clean/rebuilds for some reason. Didn’t think I’d have to play with build files, I don’t remember having to do that with previous iterations, this is just a project update

Any time you update CMakeLists.txt, or change any other files (like the files), then Android Studio usually pops up a yellow bar up the top of your source window indicating the project needs to be synced. You can either click the sync operation from that notification bar, or go to File->Sync Project With Gradle Files: