How to Use Eclipse to Debug JNI code (Java & C/C++)

For those looking to debug NDK/JNI code in the Eclipse Juno release, it is essentially built into the software after installing the Android plugins and CDT plugins. You may have issues though since there is a problem that was introduced with the C/C++ Development tools (CDT 8.1) that as of 7/24/12 has not been fixed. For details on the issue see the following link. If you just want to debug, keep reading.

http://code.google.com/p/android/issues/detail?id=33788

If it is working correctly, you simply set your breakpoints in the C and Debug As -> Android Native Application. Unfortunately, you can not debug the java and C at the same time. If the problem is in the Java and you want to debug you do so by clicking Debug As -> Android Application.

If it is not working correctly, and you want to figure out how to get it correctly, the following packages worked for me.

  Android DDMS  20.0.1.v201207132230-403220
  Android Development Tools 20.0.1.v201207132230-403220 
  Android Hierarchy Viewer  20.0.1.v201207132230-403220 
  Android Native Development Tools  20.0.1.v201207132230-403220 
  Android Traceview 20.0.1.v201207132230-403220 
  Autotools support for CDT (Incubation)    3.0.1.201202152032  
  C/C++ Development Tools   8.0.2.201202111925  
  C/C++ Development Tools SDK   8.0.2.201202111925
  C/C++ Library API Documentation Hover Help (Incubation)   
  Eclipse SDK   4.2.0.I20120608-1400    
  Tracer for OpenGL ES  20.0.1.v201207132230-403220

The android packages came from setting Work With: option on the Eclipse Help->Install New Software… dialog to

dl-ssl.google.com/android/eclipse/

The older 8.02… CDT packages came from setting the Work With: option to the Indigo release packages.

download.eclipse.org/releases/indigo

If installed, you will need to remove the Android tools, and the new version of the CDT prior to installing the old version of the CDT. Once the 8.02… version of CDT is installed, you can install the Android tools and commence debugging.

Ensure you use the Build command “ndk-build NDK_DEBUG=1”

Autotools may not be required but since it is installed I have it listed.

Note that stepping through the code can be quirky sometimes.

Leave a Comment