Debugging Cocos2D-X Android Builds through Command Prompt

If you have developed builds for iOS, you may know how excellent XCode is as a development platform. One of its best features is its integrated Debug terminal.

On Android, we have got an excellent IDE Eclipse, which has its own Debugger as well. However, due to me facing certain configuration issues with it and Cocos2D-X, I switched to the normal Text Editor+Terminal development for my personal projects. In which case, I had to struggle a bit with the debugging on terminal.

So, how do you debug an Android build on Command Prompt or Terminal. The easiest way out is just entering the following to the command prompt.



 > adb logcat


However, this will result in you being shown all events going on within your device (including the system events). So much so that it becomes almost unusable.

So we need to filter out the messages that are not coming from our game/build. For that we can use the following:



 > adb -d logcat com.yourCompany.yourApp:I *:S


You need to replace "com.yourCompany.yourApp" with the actual bundle id of your App. This will filter the lof messages to show you only the Logs that are generated by your App.

Another major requirement during debugging is to find the stack output of the point where your build may be crashing. For this, you can use the below command:


 > adb logcat | ndk-stack -sym >Path to your Project</proj.android/obj/local/armeabi


Obviously you will need to enter the proper path to the project by replacing the ">Path to your Project<" with the actual path. This will display the call stack, and at times precise file name and the line where the crash has occurred.

As a note of caution, I'd like to mention here that most of the time while trying to fix crashes I do focus too much on the point where the crash has occurred. Most of the time, that is not the point where you may have made the mistake. In my case, a whopping 80-90% of times I found my build crashed because certain objects were released elsewhere and the crash point code was actually just trying to access it.

There, this should get you started with the terminal debugging. There is still more options to explore if you want to get further deep inside the rabbit hole! ;) (Here, follow the white rabbit. Android Logging)

Ohh, and by the way, if you want your Logcat output to be slightly colored (that helps a lot actually), you can try the Python script available on Jeff Sharkey's Blog.



Comments

Popular posts from this blog

Cocos2d-X v3.x : Calling Functions after Delay

Supporting Unicode and Emoji characters in Unity3D (or other Engine) Game - The Lazy Way

[New] Cocos2DX vs. Unity. What to Choose for 2D Development?