After a 2 day struggle i managed to get box2d and cocos2d running happy (even on a hybrid project, iOS and android sharing the same code) thanks to the http://gameit.ro tutorials! I really wish I could buy him a beer!
Be sure you read and re-read his tutorials. But my main pointers are:
My main project directory is on the cocos2dx root folder. This advice is given and should be a no brainer.
Cocos2d default project creationg build an APP_MODULE called game_logic, this was killing me when i was trying to build (giving me linking errors and such). I just removed it and everything went fine! Dont know if removing it is a good idea, but my project is doing fine without it!
I will not post how my .mk files are:
Main Android.mk file (this is under the folder jni):
LOCAL_PATH := \$
subdirs := \$/../../libs/,\$)
subdirs += \$/helloworld/Android.mk
Application.mk file :
# it is needed for ndk-r5
APP_STL := stlport_static
APP_MODULES := cocos2d cocosdenshion box2d game*
Android.mk (this is under the helloworld folder, the most important one!):
LOCAL_PATH := \$
LOCAL_MODULE := game
LOCAL_SRC_FILES := main.cpp ../../../Classes/AppDelegate.cpp ../../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := \$/../../../libs/cocos2dx \$/../../../libs/cocos2dx/platform \$/../../../libs/cocos2dx/include \$/../../../libs/CocosDenshion/include \$/../../../libs/ \$/../../../libs/Box2D \$/../../../Classes
# it is used for ndk-r5
# if you build with ndk-r4, comment it
# because the new Windows toolchain doesn’t support Cygwin’s drive
LOCAL_LDLIBS := ~~L\$/../../libs/armeabi) ~~lGLESv1_CM ~~lbox2d ~~lcocos2d ~~llog~~lcocosdenshion ~~L\$/../../../libs/cocos2dx/platform/third_party/android/libraries)~~lcurl
This is where i struggled! Well, libs is a foler on my project root folder, it contains the used modules (box2d, cocos2d, cocosdenhsion), I had to copy over them from the current cocos2dx root folder because the project creation somehow was not copying the right folders (missing files and other stuff, i didnt went to further into, but i might)
build_native.sh (just changed the main processor variables):
# set params
BrasilQuestX is my main game folder and as you can see, its under the cocos2d root folder!
Im using NDK r5. The variable for the r5 directory is set under the bash_profile, but you could set under the build_native.sh just like the tutorial!
*This was pretty much all i had to do! I was pulling my hair off, untill i saw the breakout demo using box2d on gameit.ro website! Link: [http://gameit.ro/2011/09/breakout/] After downloading it and seeing how he has done it was a life changer for me and within minutes i had my project set up!(*
It uses box2d and had compiled so perfectly i looked into all the .mk files and made all the changes, after a few tweaks here and there, i managed to build everything without any compile/link errors)
I hope it helps you! I know how hard it its to get it right the first time! Will do everything i can to help you out! Good luck!