Visual Studio 2015 - debugging Android apk in 2 minutes :)

Hi,

Below 6 steps (2 minutes) how to debug cocos2d-x Android apk with Visual Studio 2015 on Android device.

  1. Build in debug mode, call “cocos deploy -m debug -p android --ndk-mode debug”
  2. In Visual Studio 2015 open apk from step 1 (File->Open->Project/Solution) point to apk
  3. Project properties-> set “Additional Symbol Search Path” to “proj.android\obj\local\armeabi”
  4. Drag and drop .cpp/.h files to Visual Studio 2015,
  5. Set breakpoint in .cpp/.h files - press F9
  6. Start debugging - press F5

Below link to full article:
https://blogs.msdn.microsoft.com/vcblog/2015/07/20/whats-new-with-visual-c-cross-platform-mobile-development/

p.s.
It works like a charm. In 2 minutes I found issue (Before I spent half day on logging, setting ndk-gdb, Eclipse, Android Studio etc)

Regards,
CHP

11 Likes

Thank you for sharing this! I will try it this weekend. FINALLY we have a decent solution to debug on Android.

Have you also found a way to debug for IOs in VS 2015 (microsoft claims, that we can remote debug with vs2015 on ios).
If this would work, we would have an “IDE to rule them all” (ios, android, win10) :heart_eyes:

I can also tell you that there is more to come here with VS2015 and Android development. Stay tuned.

Good to hear! @slackmoehrle could you tell a little bit more? Especially when (or at least in which timespan) it’s coming? :wink:
Is cross platform development for VS planned? E.g. write all the code in VS and compile / debug for all 3 OS (android, ios, win10) in VS2015? (I know that a Mac is needed for compiling IOs from VS2015, but at least there is no need to switch IDEs / computers)

I am not sure what is possible here in terms of compiling iOS and OS X apps using Visual Studio on Windows. Is there actually any offerings?

What will happen is being able to use VS to compile your Windows, WP, Androids apps. But VS 2015 only.

Yes, Microsoft claims, that cross platform c++ is possible: https://www.visualstudio.com/en-us/features/cplusplus-mdd-vs.aspx

Actually Microsoft even claimed, that they will work with Chukong Technologies: https://blogs.msdn.microsoft.com/somasegar/2015/04/17/visual-studio-for-game-development-new-partnerships-with-unity-unreal-engine-and-cocos2d/

Quote: Together, we will be working to deliver the best possible game development experiences to users of these engines from within the Visual Studio IDE, further unlocking game developer creativity and productivity.
That was last year in April :open_mouth:

I only tried to get the Android project to compile in VS2015 (Tried to import the Eclipse Project into VS2015, since there is an Eclipse importer available, then debugged the cocos python build script and tried to fill in the missing steps in VS2015) but I didn’t get it to work and since there is so little information, I stopped looking into it.
Futhermore, I did open a issue / feature request on github: https://github.com/MSOpenTech/cocos2d-x/issues/185 but that was apparently ignored. I am just curios, if it is not possible, or if they (in this case, Microsoft i think) don’t care.

Can you please explain this point how you draging files to Studio (all classes folder or some specific)? You opening empty project in Studio or how it is done?

btw if u using --android-studio flag you should add to build.gradle

android{
  buildTypes {
    debug {
        jniDebuggable true
    }
  }
}

You can for example:

  1. Select all files .cpp/.h files from Classes and just drag and drop to Visual studio windows
    https://en.wikipedia.org/wiki/Drag_and_drop
    or
  2. In Visual Studio: File->Open->file choose files from Classes
    or
  3. In Visual studio: shortcut ctrl+o

Yeah, it is really easy just drag and drop:) Was thinking about improting project somehow to studio:) But it was really just drag & drop.

I have this error, does anyone know why?

I used NDK r10e with cocos2d-x 3.8.1 and it was working fine.

That worked for me like a charm :).
Thank you @CrazyHappyGame.

One can also look at the msdn blog post:
https://blogs.msdn.microsoft.com/vcblog/2015/07/20/whats-new-with-visual-c-cross-platform-mobile-development/

if using gradle for build add this parameter to your project

Hello,
I’ve some problems to debug, I can open apk and launch with CTRL+F5 without problem on real device, but if I try to debug using F5 I have that error: “Unable to start debugging. Android command ‘run as’ failed. Package mypackage is unknown”
I used NDKr10e and cocos 3.10
Could you please help me?

Thank you.