Search code examples
androidc++android-ndkdbg

Android NDK | How to debugging app startup or suspend app until debugger connected


During investigation crash of my cocos2d-x app I faced with problem that debugger not stops in AppDelegate.cpp class at all.

My assumption is: debugger could not connect before time when this code has been executed.

Is my assumption correct? Is any workaround there?


Solution

  • I agree with fadden you can add call sleep (or usleep) function. In case cocos2d-x you should put it in beginning of void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) function

    void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, 
                                                           jobject thiz, 
                                                           jint w, 
                                                           jint h)
    {
    #if COCOS2D_DEBUG    
        sleep(30);
    #endif
        ...
    }
    

    Also you should not forget to include <unistd.h> in case usleep