7

I am to create a shared library for Android OS. Although I have done some Android apps in Eclipse I decided to start my native development with Visual Studio and vs-Android add-on:

http://code.google.com/p/vs-android/

I am really familiar with VS and Google found that add-on as one of the first results. I have gone through the whole setup procedure, installed JDK, NDK, Ant, set system variables and finally got a working project. It works like a charm! But there is a BIG drawback. I am not able to debug the native code.

I know there is NDK-GDB tool, but I am constantly failing when trying to setup it. I have read NDK-GDB.html document, threw away the initial vs-Android solution and successfully gone through the following tutorial:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

but now I am stuck again when trying to go through the:

http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/

http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/

I also tried WinGDB - just imported working Eclipse project containing both native and Java code, but it doesn't even compile.

In short, there are many pieces of the puzzle, but I am still missing some of them. I am afraid that I am missing the whole idea of debugging code with a command line tool like NDK-GDB is.

Can someone provide me some explanation and clear steps how to debug native libraries (doesn't matter if with vs-android or Eclipse or whatever else)? Please be aware I am not a Linux guru and also not familiar with cygwin or gdbserver.

vitakot
  • 3,786
  • 4
  • 27
  • 59

2 Answers2

13

The steps I take to be able to debug using ndk-gdb

To build

Set the -g compiler flag in jnk/Android.mk to build the gdb-server

LOCAL_CFLAGS := -g

Build the native lib for debugging NDK_DEBUG=1

ndk-build NDK_DEBUG=1

Set the application debuggable in the manifest.

android:debuggable=true

Open cygwin and cd to the project path. Set the path to adb.

export PATH=$PATH:/path_to_android_sdk/platform-tools

And then start gdb

ndk-gdb --verbose --adb=adb.exe

You will have to type continue when you have connected to the gdb-server

tidbeck
  • 2,363
  • 24
  • 35
  • Vita@Vita-PC ~ $ export PATH=$PATH:C:/Android/android-sdk/platform-tools Vita@Vita-PC ~ $ ndk-gdb --verbose --adb=adb.exe Android NDK installation path: /home/Vita/C:\Android\android-ndk-r7 Using specific adb command: adb.exe /cygdrive/c/Android/android-ndk-r7/ndk-gdb: line 281: adb.exe: command not found ERROR: Could not run ADB with: adb.exe – vitakot Jan 03 '12 at 22:39
  • @vitakot the paths in cygwin is different it should be `/cygdrive/c/Android/android-sdk/paltform-tools`. You can try to `cd` to the directory first to make sure you get it right. – tidbeck Jan 03 '12 at 22:46
  • I have reinstalled Cygwin and just used WinGDB: http://www.wingdb.com. It finally works great! – vitakot Jan 03 '12 at 22:47
  • `Vita@Vita-PC ~ $ cd C:/Android/android-sdk/platform-tools` `Vita@Vita-PC /cygdrive/c/Android/android-sdk/platform-tools $` – vitakot Jan 03 '12 at 22:53
  • Not sure I understand what you mean by that. I wanted you to try `export PATH=$PATH:/cygdrive/c/Android/android-sdk/platform-tools` in a Cygwin bash terminal instead of using the `C:` path. – tidbeck Jan 03 '12 at 23:01
  • OK, I am one step further, but now the cygwin tolds me: `Using final ADB command: 'adb.exe' awk: fatal: can't open source file `/home/Vita/C:\Android\android-ndk-r7/build/a wk/check-awk.awk' for reading (No such file or directory) ERROR: Could not run 'awk' command. Do you have it installed properly?` But "check-awk.awk" is there... :( – vitakot Jan 03 '12 at 23:46
  • I'm not on a Windows computer right now so I cannot test this until tomorrow but it looks like your path is wrong. – tidbeck Jan 03 '12 at 23:50
  • I finally got it working; there was a problem with the system variable ANDROID_NDK_ROOT - the paths where Cygwin was searching for the stuff were wrong. Now I am able to use even CGDB debugger: http://cgdb.sourceforge.net. But it such a pain then I will rather pay ninety bucks for a mobile version of WinGDB... Thanks for help! – vitakot Jan 05 '12 at 00:58
  • @tidbeck Your solution worked for me. I am from the future :) – Ahmed Jun 24 '12 at 03:49
  • @tidbeck I had the same issue but thanks to your answer finally I am done with setting up the `gdb server`its showing `continuing` after i enter `continue `. But what to do after that? I am clueless how to debug further how to hit break points in native code. – DeltaCap019 Jul 11 '13 at 08:55
  • @AbhinavRathore I think you should read a gdb tutorial/manual to find out how to use gdb. – tidbeck Jul 29 '13 at 09:10
1

There is a step-by-step tutorial on debugging vs-android projects with Visual Studio here: http://visualgdb.com/tutorials/android/vs-android/

Ivan Shcherbakov
  • 2,063
  • 14
  • 23