Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging native libraries for Android OS

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.

like image 958
vitakot Avatar asked Dec 29 '11 22:12

vitakot


People also ask

What are Android native libraries?

Android applications can contain compiled, native libraries. Native libraries are code that the developer wrote and then compiled for a specific computer architecture. Most often, this means code that is written in C or C++.

Can you debug an Android phone?

To enable USB debugging, toggle the USB debugging option in the Developer Options menu. You can find this option in one of the following locations, depending on your Android version: Android 9 (API level 28) and higher: Settings > System > Advanced > Developer Options > USB debugging.


1 Answers

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

like image 199
tidbeck Avatar answered Oct 02 '22 13:10

tidbeck