Android Make File (Automate)

Hey guys, I have a project that I started porting from cocos2d-iPhone, and I have to say I love cocos2d-x! I feel right at home!

Everything is going smoothly in Xcode, however this issue in Android is killing me:
http://gameit.ro/2011/08/adding-a-new-cpp-file-to-the-android-build-process-or-how-to-handle-the-undefined-reference-to-vtable-for-gameoverscene-error/

I really need to find a way to automate the process. Each time I add a cpp file (Which I have 114 file in total) I have to edit the make file, in order to test it on android.

Could anyone help me automate this?

I can write bash scripts, but I am not a pro. The best I could do now, is iterate the *.cpp files, and generate “…/Clases/Class1.cpp …/Classes/Class2.cpp” … etc, then copy it into the make file. I would rather use a more convenient method that does not involve openning the make file and editing it manually…

Thanks

1 Like

After looking around for a while, there seems to be a feasible solution

Writing a bash script that would iterate the *.cpp file, and generate a file (call it classes_vars for example), and in that file we output ANDROID_CLASSES=“…/Clases/Class1.cpp …/Classes/Class2.cpp”. Finally, just link that file somehow in the make file, and use the $ANDROID_CLASSES variable.

I haven’t written the script yet, and would love to at least hear some thoughts about this?!

one thing you can do by modifying Android.mk in JNI folder and Genrating a Andriod.mk file which points to game classes.

setp 1. put all the .cpp and .h file is Classes folder [without any subfolders] … i know sounds unorganized but it works.
step 2. : download “genrateMakeFile.sh”
step 3 : put it in proj.android folder
setp 4 : modify Android.mk in JNI folder like

search for line :

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

to

LOCAL_WHOLE_STATIC_LIBRARIES := cocos_game_common cocos2dx_static cocosdenshion_static cocos_extension_static

add “cocos_game_common”

or if you see structure like this

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

to

LOCAL_WHOLE_STATIC_LIBRARIES := cocos_game_common
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

“cocos_game_common” that is name of the module for all the game classes in /Classes folder

THEN

at the end of Android.mk file

add one line like

$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)

to

$(call import-module,gameFolder/Classes) \
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)

gameFolder is the name of the folder in your COCOS2DX root in which your cocos2dx project in generated.

AFTER modifing the make file just put one line in build_native.sh , you must add it to first line of build_native.sh

./genrateMakeFile.sh

DONE

whenever you run ./build_native.sh all the classes in /Classes folder will be complied , limitation of my script is .cpp and .h should not be in subfolders.

Whenever i need to test for android i do this way only. :slight_smile: peace .

:smiley: Perfect!

This should be a sticky thread or something, so everyone can benefit from it.

Cheers! :smiley:

:slight_smile: thank you

If you want to get rid of placing resources and classes one by one into /Classes and /Resources , as i am using Xcode then
I have one more modification to automatically build /Classes and /Resources folder out of the subfolders in them.

step 1. put rebuildDirectoryStructures.sh in proj.android folder.
step 2. add one more line in build_native.sh … this line should be at first.

./rebuildDirectoryStructures.sh

step 3. I forget to tell please perform chmod a+x on both files.

if your folders or files contains spaces then these both scripts will not work … ++

thank you :slight_smile:

Wait, am I missing something, I can’t find the “genrateMakeFile” attached? :stuck_out_tongue:

ohh sorry

now check

OK, it’s working :smiley:

I have a few small notes:

  1. since I am lazy, I copy/pasted your code, and there was a typo that we missed :stuck_out_tongue:

./genrateMakeFile.sh

./generateMakeFile.sh

  1. In the Android.mk file , we should modify the old LOCAL_SRC_FILES, and make it only point to classes outside the Classes folder, to avoid duplicate inclusion:

LOCAL_SRC_FILES := hellocpp/main.cpp

Thanks a lot Nitesh :smiley:

:smiley: …. 2nd point i forget to mention :slight_smile: …. i am glad to share something … good luck for your game:)