如何调试cocos2d-x 3本机代码在Android设备上 [英] How to debug cocos2d-x 3 native code on android device

查看:316
本文介绍了如何调试cocos2d-x 3本机代码在Android设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何cookbook /教程如何构建在调试构建一个cocos2d-x 3.1项目为Android和如何调试它直接在设备上。请通过指出步骤来帮助。

I could not find any cookbook/tutorial how build in debug build a cocos2d-x 3.1 project for Android and how to debug it directly on device. Please help by pointing out steps.

我所做的和我遇到了什么问题:

What I do and what problems I have:


  • cd proj.android

  • cocos compile -p android -m debug --ndk-mode NDK_DEBUG = 1 (使用调试信息构建)

  • cocos run -p android -m debug 在设备上部署

  • 在设备上运行应用

  • cd jni

  • ndk-gdb

  • cd proj.android
  • cocos compile -p android -m debug --ndk-mode NDK_DEBUG=1 (to build with debug info)
  • cocos run -p android -m debug to deploy on device
  • run app on the device
  • cd jni
  • ndk-gdb

Nareks-MacBook-Pro:jni Narek$ ndk-gdb
jni/Android.mk:67: *** Android NDK: Aborting.    .  Stop.
ERROR: The device does not support the application's targetted CPU ABIs!
       Device supports:  armeabi-v7a armeabi
       Package supports: Android NDK: 

进入 Application.mk 我已添加:

APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-10

但它没有帮助。我做错了什么?

but it did not help. What I do wrong?

EDIT:添加 ndk-build DUMP_APP_ABI 命令的结果在项目中调用 jni 目录:

Adding result of ndk-build DUMP_APP_ABI command called in projects jni directory:

Nareks-MacBook-Pro:jni Narek$ ndk-build DUMP_APP_ABI 
Android NDK: /Users/Narek/NoorGames/Games/test2/proj.android/jni/Android.mk: Cannot find module with tag '.' in import path    
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
Android NDK: The following directories were searched:    
Android NDK:         
/Users/Narek/NoorGames/Games/test2/proj.android/jni/Android.mk:67: *** Android NDK: Aborting.    .  Stop.


推荐答案

这里是step-by- cocos2d-x 3.x在Android设备上。

Here is the step-by-stet tutorial to debug cocos2d-x 3.x on Android device. Please correct or optimize my steps if you do it in better way.


  1. cd proj.android

  2. cocos compile -p android -m debug --ndk-mode NDK_DEBUG = 1

  3. cocos run -p android -m debug 在设备上部署(有时它会重建,我不知道为什么)。此命令卸载以前的安装,安装新的安装并在设备上运行应用程序。

  4. 确保在 proj.android/libs/armeabi 目录中有以下文件 gdb.setup,gdbserver,libcocos2dcpp.so

  5. 还要确保 /proj.android/jni/obj/local/armeabi 目录中有 app_process,gdb.setup,libc.so,linker li>
  6. ndk-gdb (重要的是,这应该在项目目录中调用,而不是在 jni 目录)

  1. cd proj.android
  2. cocos compile -p android -m debug --ndk-mode NDK_DEBUG=1 (to build with debug info)
  3. cocos run -p android -m debug to deploy on device (sometimes it rebuilds, and I don't know why). This command uninstalls former installation, installs the new one and runs the app on the device.
  4. make sure in proj.android/libs/armeabi directory you have the following files gdb.setup, gdbserver, libcocos2dcpp.so
  5. also make sure that in /proj.android/jni/obj/local/armeabi directory you have app_process, gdb.setup, libc.so, linker
  6. ndk-gdb (important! this should be called in projects directory, not in jni directory)

如果它工作,那么恭喜!但在此步骤中,您可能会看到以下错误消息:

If it worked then congratulations! But in this step you may see such error message:

Nareks-MacBook-Pro:proj.android Narek$ ndk-gdb
jni/Android.mk:67: *** Android NDK: Aborting.    .  Stop.
ERROR: The device does not support the application's targetted CPU ABIs!
       Device supports:  armeabi-v7a armeabi
       Package supports: Android NDK: 

不要担心:)。让我们看看有什么错误:

Don't worry :). Lets see what is wrong:


  1. 这里是 ndk-build DUMP_APP_ABI jni 目录中调用$ c>命令:

  1. here is the result of ndk-build DUMP_APP_ABI command called in project's jni directory:

Nareks-MacBook-Pro:jni Narek $ ndk-build DUMP_APP_ABI
Android NDK:/Users/Narek/NoorGames/Games/test2/proj.android/jni/Android.mk:在导入路径中找不到带有标签'。'的模块

Android NDK:确定您的NDK_MODULE_PATH变量已正确定义?

Android NDK:搜索以下目录:

Android NDK:

/ Users / Narek / NoorGames / Games / test2 / proj.android / jni / Android.mk:67:*** Android NDK:Aborting。 。停止。

Nareks-MacBook-Pro:jni Narek$ ndk-build DUMP_APP_ABI Android NDK: /Users/Narek/NoorGames/Games/test2/proj.android/jni/Android.mk: Cannot find module with tag '.' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/Users/Narek/NoorGames/Games/test2/proj.android/jni/Android.mk:67: *** Android NDK: Aborting. . Stop.

正如您可以看到 NDK_MODULE_PATH 缺失。要获取该值,请执行以下操作。转到您编译代码的步骤。在命令 cocos compile -p android -m debug --ndk-mode NDK_DEBUG = 1 的第一行执行你可以看到这样:

As you can see NDK_MODULE_PATH is missing. For obtaining the value do the following. Go to step where you compiled code. In first linse of execution of command cocos compile -p android -m debug --ndk-mode NDK_DEBUG=1 you can see something like this:

Runing command: compile
Building mode: debug
building native
NDK build mode: NDK_DEBUG=1
The Selected NDK toolchain version was 4.8 !
running: '/Users/Narek/NoorGames/android-ndk-r9d/ndk-build -C /Users/Narek/NoorGames/Games/test2/proj.android -j1 NDK_MODULE_PATH=/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d:/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d/cocos:/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d/external'




  1. 上面的日志可以看到 NDK_MODULE_PATH 的必要值。执行以下命令 export NDK_MODULE_PATH = / Users / Narek / NoorGames / Games / test2 / proj.android /../ cocos2d:/Users/Narek/NoorGames/Games/test2/proj.android/ .. /cocos2d/cocos:/Users/Narek/NoorGames/Games/test2/proj.android /../ cocos2d / external (注意不要复制我的路径)

  1. copy from the log above you see the necessary value of NDK_MODULE_PATH. Execute the following command export NDK_MODULE_PATH=/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d:/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d/cocos:/Users/Narek/NoorGames/Games/test2/proj.android/../cocos2d/external (be attentive to copy your path not mine)

就是这样。现在在设备上运行游戏, cd proj.android ,调用 ndk-gdb ,你应该能够使用gdb 。

That's it. Now run game on device, cd proj.android, call ndk-gdb and you should be able to debug with gdb.

我个人寻找这类教程已经超过20天了。我希望你喜欢你的调试已经。 :)并感谢@VikasPatidar帮助您 ndk-build DUMP_APP_ABI 步骤!

I personally looked for this kind of tutorial already more than 20 days. I hope you enjoy your debugging already. :) And thank you @VikasPatidar for your help with ndk-build DUMP_APP_ABI step!

EDIT1:如您所评论的Vikas,您可以在 Android.mk NDK_MODULE_PATH c>文件如下:

As commented Vikas you can add NDK_MODULE_PATH in Android.mk file like this:

NDK_MODULE_PATH := $(LOCAL_PATH)/../../../../cocos
NDK_MODULE_PATH += $(LOCAL_PATH)/../../../../external






EDIT2:如果您的应用程式在这里崩溃,是一种非常强大且简单的方法来防止直接调试问题:


If your app crashed here is a very powerful and easy way to investigate the problem by preventing direct debugging:

adb logcat | $NDK_ROOT/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi

这篇关于如何调试cocos2d-x 3本机代码在Android设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆