I have to say that I loved the new script that automates creating a cocos2d-x project for all platforms, and ready to use out of the box!
I am still finding the need to update the android.mk file manually to include all the classes in the Classes folder a bit irritating. Isn’t there an automation coming up for this?
And, also, in iOS I can easily make folders in the Classes directory, then #include them in any source file as follows:
In Classes/dir1/class1.cpp #include "class2.h"
But, in android, I have to explicitly do: #include "../dir2/class2.h"
As far as the #include’s go I think it won’t be possible (or will be extremely hard) to do.
When you add class files in XCode it stores their paths in its project file, so in the end it automatically provides the compiler and linker with necessary information “behind your back”.
With Android you have to give relative paths, because the compiler there is not integrated with the IDE, so it doesn’t know where to look for included files.
As to the Android.mk autmation, I just had an idea I want to try, and if successful I will post it here.
Well, I’ve tried, but couldn’t do it…
I tried writing a script that would automatically generate the Android.mk file, and I got this part, but for unknown reasons to me it broke my project - to be specific, when I introduced the automatically generated file to my project and tried to run it, I suddenly said that the file “jni/hellocpp/main.cpp” cannot find “#include”AppDelegate.h“”. I haven’t changed anything in this project, and I checked before introducing the generated file that it built & run correctly.
Awesome stuff, man!
This looks really clean and simple, and easy to incorporate!
I have to mention there was an earlier attempt to automate the process, but it wasn’t perfect, cause it didn’t allow for subfolders to exist within the Classes directory.
You can fin it here: http://www.cocos2d-x.org/boards/6/topics/16846
I have very few notes for other developers looking to use this in their project:
1- create the mkHelper.sh in your proj.android folder, with your build_native.sh.
2- make sure you chmod u+x mkHelper.sh to avoid sudo’ing the ./build_native.sh
3- make sure you update the mkHelper.sh script to whatever your Android.mk file contains initially. So, in my case, I had to add the chipmunk, box2d, and libcurl imports.
Something broke in the script for some reason, and the game builds successfully, but started crashing on launch with the following error:
@
AndroidRuntime The import org.cocos2dx cannot be resolved
@
The solution was, to replace:
@
echo ‘LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static chipmunk_static box2d_static’
@
Well, I wouldn’t be so sure, as if this was actually a solution to this, as this error seems to be java-based. Have you restarted Eclipsed when figuring this out?
Maybe it just got stuck during some maintenance-ish task while you tried to run your project and simply couldn’t access the cocos library.
#!/bin/bash
if diff <(find -L ../Classes -name \*.cpp -print | ./mkHelper.sh) <(cat jni/Android.mk); then
echo "Generated Android.mk the same as previous, not updating."
else
echo "Generated Android.mk different than previous, updating."
find -L ../Classes -name \*.cpp -print | ./mkHelper.sh > jni/Android.mk
fi