Android NDK Debug

We sometimes want to debug Native code(C/C++) in Android.

Over Android ADT r20, we can debug native code easily by eclipse. No command line, No additional code, No Complicated setting.

My Env: Mac OS X 10.7, Eclipse 4.2, Android Eclipse v22, Android 4.0, NDK 14(Android4.0)

Just only setting by GUI operation. Happy :)


We need only 3 steps

    1. Add ndk-build NDK_DEBUG=1 to build option in eclipse
    2. Enable Android debuggable in AndroidManifest.xml
    3. Debug as Android Native Application

Enable NDK Debug to add build command NDK_DEBUG=1

Eclipse -> Project -> Properties -> C/C++ Build

Remove check of Use default build command, and add NDK_DEBUG=1 after ndk-build


** Should remove when releasing **

Enable Android debuggable in AndroidManifest.xml

To enable debug, please enable debuggable in AndroidManifest.xml.

Click and open AndroidManifest.xml, you can see Debuggable

debuggable manifest

In case of xml, you can add under application tag

        android:theme="@style/AppTheme" android:debuggable="true">

Debug as Android Native Application

This is the last point of this topic.

Eclipse -> Run -> Debug As -> -> Android Native Appliation

android native application
In this image, 3rd one.

** You never select Android Application, in that case, debug Java code only

After that, you can set break point in Native Code! Enjoy!


Unfortunately, we can’t debug Java codes and Native code at the same time :(
Can’t select both Android Application and when debugging


If you want to debug built library, which is share library(.so) compiled outside of Android Project(with toolchain or something).
You need to locate source codes under your machine.

That is just same as general Java Source code Attachment to debug Java code!

Additional Info

If you want to debug shared library which is made by other project.
That is copy shared library(.so) in project.
In that case, you need to build shared library with debug symbol(gcc option -g)
And also, you need to build library on this same machine you use in target project because shared library need to find