http://blog.csdn.net/tt5267621/article/details/8940768
Prerequisites:
First read this article: http://blog.csdn.net/tt5267621/article/details/8941084 (first ecplise already can compile cocos2d-x see this article)
- You have downloaded the coccos2d-x and NDK and will
build_native.sh
compile the Cocos2d-x project with Eclipse
Installing the NDK Plugin
English good students can directly see the official instructions using the NDK plugin, here I briefly translated
- Open Eclipse, select Help->install New software in the menu ...
- Pop-up window in the first box "work with:" followed by input
https://dl-ssl.google.com/android/eclipse/
- Wait a moment, and the following will come out "Developer Tools" and "NDK Plugins", all selected, Next, agree agreement, etc after installation, restart Eclipse
- After eclipse restarts, go to ECLIPSE->PREFERENCES->ANDROID->NDK and set up your NDK directory here, like mine, which I set to
/android/android-ndk-r8e
- Installation Complete
Import an example game under the Cocos2d-x directory
Here I use cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame
this little game as an example to illustrate.
Let's say your eclipse is clean, that is, the Package Explorer bar on the left is empty.
- Import Libcocos2d-x to Eclipse, right-click the Package Explorer blank area, import->existing Android Code into Workspace, and then in the next window root directory where you navigate to
cocos2d-2.1rc0-x-2.1.3/cocos2dx/platform/android/java
this directory, select LIBCOCOS2DX, Import
- Follow the method above to import
cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/proj.android
- Now there are two items in eclipse: Libcocos2dx,simplegame
Setup uses Ndk-build to compile
Because we do not use build-native.sh to compile, so we have to get the resource file in the Android project assets, specifically, the cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/Resources
following all the files copied to the cocos2d-2.1rc0-x-2.1.3/samples/Cpp/SimpleGame/proj.android/assets
following
Ready to work.
- In Eclipse's Package Explorer, right-click on the Simplegame project and select "Properties" to open the project properties box
- Set Tool Chain Editor as follows
- Set the Ndk-build command again, for
ndk-build NDK_DEBUG=1
, OK, close the dialog box
- This time, you choose Project->build All, there will be an error, meaning that the Ndk_module_path setting is not correct
- Here we do not set Ndk_module_path, because set it will let us not debug C + + code, solve the above problem is: the compilation process needed to copy the library to the system default Ndk_module_path, follow me to do
- Copy these 4 directories under the cocos2d-2.1rc0-x-2.1.3 directory
cocos2dx,CocosDenshion,extensions,external
to your ndk's sources directory, take my computer for example, is/android/android-ndk-r8e/sources
- Copy all of the cocos2d-2.1rc0-x-2.1.3/cocos2dx/platform/third_party/android/prebuilt directories into the sources directory of the NDK
- So we copy the directory to the NDK's sources directory.
cocos2dx,CocosDenshion,extensions,external, libcurl,libjpeg,libpng,libtiff,libwebp
- Back to eclipse, project->build all again, should compile successfully
Modify the project file structure so that the CDT can recognize our C + + files
In order to give C + + a breakpoint, we have to modify the current project file structure
- Move cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/classes directory to cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/ Proj.android/jni below
- Modify the Cocos2d-2.1rc0-x-2.1.3/samples/cpp/simplegame/proj.android/jni below the android.mk, put the original
In Android.mk:
LOCAL_SRC_FILES := hellocpp/main.cpp ../../Classes/AppDelegate.cpp ../../Classes/HelloWorldScene.cpp ../../Classes/GameOverScene.cpp
Revision changed to
LOCAL_SRC_FILES := hellocpp/main.cpp Classes/AppDelegate.cpp Classes/HelloWorldScene.cpp Classes/GameOverScene.cppLOCAL_C_INCLUDES := $(LOCAL_PATH)/Classes
That is, to point the file to the correct location
Project->build all compile project, should be able to compile successfully
Debugging
- We give the HelloWorldScene.cpp file in the classes directory the Cctouchesend method next breakpoint, so that after the game runs, click on the screen should be able to trigger our breakpoint
- Connect your phone to your computer, right-click Simplegame, choose Debug as->android Native Application
- If you need to select a phone, choose the one you want to debug
- After the game runs up, touch the screen and you can see
Eclipse automatically switches to the debug interface, and the success of the breakpoint down, and the variable can be in the right window to view the Debug button on the interface is no longer said, is to continue to execute, step into what a few, find out how to know
enjoy!
[Original article, reprint please specify]
PS: In the above operation we copied a lot of cocos2dx files to the NDK directory below, a bit cumbersome to do, so the directory is to avoid to set Ndk_module_path, if once set up Ndk_module_path, will make debugging not line, There may be a better way, if you know, or if you have any questions, you can leave a comment directly under the article.
Debug Cocos2d-x C + + code with Eclipse (write + True machine Debug, discard vs)