10
votes

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 (to build with debug info)
  • cocos run -p android -m debug to deploy on device
  • run app on the device
  • cd jni
  • ndk-gdb

And I get this error:

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: 

Into Application.mk I have added:

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

but it did not help. What I do wrong?

EDIT: 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.
1
Can you check if there are obj files generated for respective ABI's in proj.android\obj\local\armeabi and proj.android\obj\local\armeabi-v7adirectories? - Vikas Patidar
@VikasPatidar in those directories I have some .a and .so files (libcocos2d.a, libcocos2dcpp.so, libbox2d.a) and also two directories: objs and objs_debug. In each of these directories I have the following directories box2d_static, cocos2dcpp_shared, cocos_extension_static.... In its turn in there directories there are object files of other directories with object files. Is this correct? - Narek
use ndk-build DUMP_APP_ABI to find correct ABI and then change it in Application.mk Also make sure APP_PLATFORM is same as running on device. e.g. android-10 is for Android 2.3.3 is version of running device then also update AndroidManiefest.xml to correct target and minimum versions. Set them as android:minSdkVersion="10" android:targetSdkVersion="10" Keep both as same. I have tried with cocos2dx 3.0 version with NDK-r9d in Eclipse. - Vikas Patidar
@VikasPatidar thanks for your help. Please see the result of ndk-build DUMP_APP_ABIin my edit question text. - Narek
@VikasPatidar I think you saved my life :) After using ndk-build DUMP_APP_ABI I saw that NDK_MODULE_PATH is missing. I called cocos compile -p android -m debug --ndk-mode NDK_DEBUG=1. This command shows the NDK_MODULE_PATH that should be set. I have exproted NDK_MODULE_PATH to /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 and it solved the problem. - Narek

1 Answers

25
votes

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 (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. 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: 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.

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. 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)

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

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: 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

It prints the crash dump.