【COCOS2DX-ANDROID-游戏开发之二五】 调试 C++代码

cocos2dx开发游戏后,移植到android后,因为android调用C++代码生成的.so库,一旦C++代码出现问题,仅靠打印代码输出信息那是远远不够的,正所谓欲先攻其事,必先攻其器,还是得配置好Eclipseandroidcocos2dxC++代码调试,这样才能事半功倍。

 

官方配置链接:
http://www.cocos2d-x.org/wiki/How_to_debug_cocos2d-x_games

 

 

cocos2dx网站上已经有android调试C++的说明了,我添加了一下补充和说明,如有错误,敬请指明

 

 

Debug Cocos2d-x C++ games in eclipse forandroid platform

Use the HelloCppas a example.

1.     Import HelloCpp and libcocos2dx intoeclipse.
HelloCpp is located in [cocos2d-x]/samples/Cpp/HelloCpp/proj.android.
libcocos2dx is located in [cocos2d-x]/cocos2dx/platform/android/java.

2.     Right-click the HelloCpp project,
Select the menu"Properties"->"Android"->"Project Build Target" 
Set the Android SDK version to that had installed on your PC or MAC.
Then select the menu "Project" -> "Clean..."

3.     Set the NDK_ROOT environment by selectthe menu "C/C++ build " -> "Environment"

4.     Modify build_native.sh and add debugoptions.
Change

"$NDK_ROOT"/ndk-build$PARALLEL_BUILD_FLAG -C


to

"$NDK_ROOT"/ndk-buildNDK_DEBUG=1 $PARALLEL_BUILD_FLAG -C

      在发布release的时候注意更改回来

5.     这一步官方步骤上没说,我们要将C/C++ Build->BuildCommand更改为 build_native.sh如下图,这样子,编译器才知道我们需要编译哪些C++代码(ps:${workspace_loc:/ptf}是我的工程,你需要更改回自己的工程)


6.     Open AndroidManifest.xml and changeminSdkVersion to 14 or higher.

在调试的时候是14,如果是14以下会报错误的,我轨迹是C++调试需要的最低版本吧,好吧这不是重点。重点是最后发布的时候要更改回8(你想运行的最低android版本),这样才能支持android2.2,

7.     Select the menu "Project"_> "Build Project" to build HelloCpp.
Then click "Debug as" _>"Android Native Application" torun the application.
You may see below error:

Unknown Application ABI:


To fix this error, copy [cocos2d-x]/cocos2dx to [ndk-dir]/sources/.
And move directories under cocos2dx/platform/third_party/android/prebuilt/ to[ndk-dir]/sources/.
After that, additional directories include cocos2dx, libcurl, libjpeg, libpng,libtiff and libwebp will under [ndk-dir]/sources/.


8.     To set breakpoint, there are someadditional steps.
Switch to C++ View.
Delete folders "Classes", "cocos2dx" and"extensions" in eclipse project.
Right-click on HelloCpp project and then select properties,
Switch to table “Source Location” under “C/C++ General / Paths and Symbols”.
Click “Link Folder”, check “Link folder in the file system" and set it’svalue to "PARENT-1-PROJECT_LOC/Classes”, then click OK.
After that here is a folder named “Classes” in eclipse project and can browserc++ source code.

Use the same way to add “Resources” folder, the value for “Link folder in thefile system” is "PARENT-1-PROJECT_LOC/Resources”.

 

添加C++代码这一步,我用的不是官方给出的这种方法,我的做法是:project->new folder->Advance->Linkto alternative location(Linked Folder)->选择C++代码目录,

一样可以编译

 

 

9.     Open HelloWorldScene.cpp and turn tomenuCloseCallback, set a breakpoint.
Select "Debug as"->"AndroidNative Application”, now you can debug c++ in eclipse.

 



然后就可以加断点调试了,这是我个人配置时遇到的问题,如果你发现了任何错误的地方,请告诉我~

 

以下我总结了几点android下发布release版本时需要注意的事情,大家可以参考下:

1.build_native.sh下 "$NDK_ROOT"/ndk-build NDK_DEBUG=1 $PARALLEL_BUILD_FLAG -C 更改为 "$NDK_ROOT"/ndk-build $PARALLEL_BUILD_FLAG -C

2.AndroidManifest.xml下 android:minSdkVersion更改为8

3.AndroidManifest.xml下 <Application android:debuggable="true" >去掉调试

4.工程->properties->C/C++Build->BuildCommand下 NDK_DEBUG=1 V=1 去掉测试参数

 

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值