Android NDK with Visual Studio-ThrowExceptions

Exception or error:

I’d like to build some native libraries for android using the NDK (native development kit), but i’d like to use Visual Studio 2010 to do it. I’ve googled quite a bit but haven’t found any information on it. Does anyone have any experience with this and know the steps necessary to make this happen? I have CYGWin installed, made sure i get Make (per the NDK instructions), but i’m not really sure of the next steps in terms of setting up the project, compiler in visual studio, etc.

If anyone knows of any write-ups, tutorials, or links to sample projects, that would be awesome, as there isn’t much on google yet.

thanks!

How to solve:

Here’s another solution, which integrates the NDK fully within Visual Studio. No makefiles. It behaves like a proper Win32 project:

###

Here’s an excellent blog post about how you can configure your environment to debug android NDK code using Visual Studio.

###

Visual Studio is officially not supported.

Some problems (but not limited to):

  • MSVS cannot create the proper ARM binaries
  • Android makefiles (.mk) are not supported by MSVS

There are however, third party solutions:

You might want to check out DS-5 as well, though it’s not Visual Studio.

###

The answer depends on what kind of integration you require.

To just build the native Android code from Visual Studio you can create a new Makefile project, and make it run ndk-build.cmd when you press “build”. If you would like to get the error messages mapped as well, you will need to parse the output of ndk-build.cmd and convert it to a format that Visual Studio can udnerstand.

If you want to debug your native Android code from Visual Studio, you will need a third party tool that will control ndk-gdb on behalf of Visual Studio and provide workarounds for several bugs (e.g. rebind breakpoints when libraries are loaded).

You can try our VisualGDB for Android tool that does exactly that – creates projects that wrap ndk-build and controls NDK debugger on behalf of Visual Studio. If you need more information, there is a step-by-step tutorial available.

###

I have not found a direct clean solution, here is my workaround.

I develop my native code on VS as a static library, and use some test project to try it as a console aplication.
When it is ok, from cygwin I use a little bash script that copies all needed files to the jni folder and launch the standard android ndk make command. (also copy some file to assets folder when needed), producing the executable in the right folder.

To use the pthreads I have linked my projects to pthreads-win32.

The only files I do not compile in VS are the jni code.

I hope this can help you.

###

There’s also a couple of other third party alternatives for developing ANdroid apps with VS in addition to those above. There is the open source dot42 located at http://www.dot42.com and Remobjects, http://www.remobjects.com , which allows you to program in c#, Pascal, and Swift. I have played with the trial of Remobjects and am now starting to play around with dot42.

My use of the remobjects trial allowed me to recreate in c# the first five chapter projects in the textbook of the Android course I took. I haven’t had the same success with dot42 so far but I need to find some time to really give it a chance.

Leave a Reply

Your email address will not be published. Required fields are marked *