I just checked out the latest commits from the gles20 branch. I created an iPhone (cocos2dx_box2d) and an Android projects and merged them together. The Box2D code was copied into the merged project.
The merged project compiles well with Xcode. However, when I use the build_native.sh to build android. It’ won’t compile.
I understand that something must be missing in either the Android.mk or the build_native.sh or both. But I couldn’t figure out how to fix it.
Here’s the log when I tried to build.
Using prebuilt externals
make: Entering directory `/Users/diwwu/Desktop/Projects/tws/tws/proj.android’
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : game_shared <= main.cpp
In file included from jni/helloworld/main.cpp:8:
jni/…/…/Classes/HelloWorldScene.h:13:19: error: Box2D.h: No such file or directory
In file included from jni/helloworld/main.cpp:8:
Yes it’s all about the compiler couldn’t find the Box2D root. But it’s more complicated than fixing that one line in .mk file.
I looked at the past threads on the same issues but all of them are a little out of date, since the .mk and the build_native.sh have been changed a lot in recent Cocos2d-X commits.
That works because your compiler is set to look for the classes folder. You just need to include the box2d root path into the LOCAL C INCLUDES.
If i remove my local c includes pointing to my box2d foler, i get the same error.
jni/…/…/Classes/Game_PhysicsController.h:12:19: error: Box2D.h: No such file or directory
I dont see how it is complicated. Even though mk changed, you still can point your local c includes on the android.mk even on the 13 beta version. Thats just a compiler setting telling the compiler to look for headers on those folders… and your error is just the compiler telling you, you did not point to him where those headers are located. Simple as that.
Let us know if your compiler still cant find the header.
I followed your method. Now that the compiler could find Box2D.h, but there are some new errors.
jni/…/…/libs/Box2D/Box2D.h:34:37: error: Box2D/Common/b2Settings.h: No such file or directory
jni/…/…/libs/Box2D/Box2D.h:35:33: error: Box2D/Common/b2Draw.h: No such file or directory
jni/…/…/libs/Box2D/Box2D.h:36:34: error: Box2D/Common/b2Timer.h: No such file or directory
jni/…/…/libs/Box2D/Box2D.h:38:50: error: Box2D/Collision/Shapes/b2CircleShape.h: No such file or directory
It seems that there’s something wrong with my folder structure, or the way those files are included in the Box2D.h
Everything is correct, that is the way the folder works in Box2D… what is missing, is that you should point also to the root of where the folders are included (this includes, cocos2dx, CocosDenshion, Box2D etc…)
As you see, box2d header file expects that you also point to the root folder of where Box2D root folder is, thus, the Box2D folder as the first folder.
Funny enough, cocos2dx default project creation should have already done that for you. Are you sure you used the latest create-android-project.sh to create your code ? (beta 13)
You could try and add the root folder as well to your LOCAL_C_INCLUDES, ex;
Finally, I did exactly what joe espindola said and the problem solved. Thanksjoe espindola!
And actually there’s one gotcha thing here.
If I use the build_native.sh to build the original android project created inside the Cocos2d-X folder, it compiles well.
However, if I copied and merged the same android project inside the newly created iPhone project, it started reporting missing Box2D.h errors. @joe espindola ’s solution was able to fix that.
As it turns out, the cpp files (let’s call them files A) in the /Classes folder inside the newly created iPhone project are different from the cpp files (let’s call them files B) in the /Classes folder in the original android project.
Specifically, the gotcha thing is, files A has code like include “Box2D.h” while files B doesn’t. As a result, if I compile the code in the original android folder, it compiles well and no errors are found (because it doesn’t try to link Box2D). But if I compile the code in the newly created and merged iPhone project folder, “Box2D.h” is reported missing.