<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Android blog</title>
	<atom:link href="http://mhandroid.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mhandroid.wordpress.com</link>
	<description>by Martin Hejna</description>
	<lastBuildDate>Thu, 23 Feb 2012 13:45:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mhandroid.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Android blog</title>
		<link>http://mhandroid.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mhandroid.wordpress.com/osd.xml" title="Android blog" />
	<atom:link rel='hub' href='http://mhandroid.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Multithread C/C++ Debugging on Emulators and Rooted Devices from Android 1.5</title>
		<link>http://mhandroid.wordpress.com/2011/01/25/multithread-cc-debugging-on-emulators-and-rooted-devices-from-android-1-5/</link>
		<comments>http://mhandroid.wordpress.com/2011/01/25/multithread-cc-debugging-on-emulators-and-rooted-devices-from-android-1-5/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 16:21:41 +0000</pubDate>
		<dc:creator>MartinH</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[ndk]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://mhandroid.wordpress.com/?p=21</guid>
		<description><![CDATA[In Android 2.2 Google announced ndk-gdb script which ease the debugging on the device. Later it turns out that it is not capable of debugging any other thread than the main thread. In Android 2.3 Google ships fixed setup so &#8230; <a href="http://mhandroid.wordpress.com/2011/01/25/multithread-cc-debugging-on-emulators-and-rooted-devices-from-android-1-5/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=21&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In Android 2.2 Google announced ndk-gdb script which ease the debugging on the device. Later it turns out that it is not capable of debugging any other thread than the main thread.</p>
<p>In Android 2.3 Google ships fixed setup so you are now finally able to debug multithread application.</p>
<p>In fact multithread debugging is possible at least from Android 1.5. But you have to set up the environment yourself. Due to permissions limitation it is only possible on rooted devices. But it is possible on emulator as emulator is always rooted!</p>
<p><span id="more-21"></span></p>
<p>Here is a small shell script which does everything for you. It will start gdbserver on the device, gdb on PC and connect them together. It will also set up paths correctly so gdb can find its unstripped libraries on PC while having stripped libraries on the device.</p>
<p>Run this script from your project root directory. You have to modify <em>APP_PACKAGE</em> and <em>ANDROID_TARGET</em> variables to match your project settings. You also need to have you project compiled in debug mode. This can be done by running <em>ndk-build NDK_DEBUG=1</em> or by setting <em>android:debuggable=&#8221;true&#8221;</em> in <em>AndroidManifest.xml</em> and compiling normally.</p>
<p><pre class="brush: bash;">
#!/bin/bash
# Martin Hejna (c) 2011
# martin.hejna@gmail.com
# CC-by


## Comment out for quiet run
set -x

# Set those variables to match your application
[ &quot;$APP_PACKAGE&quot; ] || APP_PACKAGE=&quot;com.example&quot;
[ &quot;$ANDROID_TARGET&quot; ] || ANDROID_TARGET=&quot;android-9&quot;

# Set installation paths of SDK and NDK
[ &quot;$ANDROID_SDK&quot; ] || ANDROID_SDK=&quot;/home/martin/Android/android-sdk-linux_86&quot;
[ &quot;$ANDROID_NDK&quot; ] || ANDROID_NDK=&quot;/home/martin/Android/android-ndk-r5&quot;

# adb and gdb executable paths
ADB=&quot;$ANDROID_SDK&quot;/platform-tools/adb
GDB=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb

# Check we are in application root path (the one with AndroidManifest.xml in it)
APP_ROOT=`dirname $0`
if [ ! -f $APP_ROOT/AndroidManifest.xml ]
then
    echo This script must be run from package root directory
    echo This is the directory with AndroidManifest.xml in it
    exit 1
fi

# Path to unstripped versions of native .so libraries
UNSTRIPPED_SO_LIB=&quot;$APP_ROOT/obj/local/armeabi&quot;
APP_PROCESS=$UNSTRIPPED_SO_LIB/app_process
APP_LIBC_SO=$UNSTRIPPED_SO_LIB/libc.so
if [ ! -d $UNSTRIPPED_SO_LIB ]; then
    echo Error: Directory $UNSTRIPPED_SO_LIB does not exist
    exit 1
fi

# Use cgdb if available
if which cgdb &gt; /dev/null
then GDB_CMD=&quot;cgdb -d $GDB --&quot;
else GDB_CMD=$GDB
fi

# We use same port number on pc and on device
DEBUG_PORT=5039

# File with gdb setup instructions (executed when gdb starts)
[ &quot;$GDB_SETUP&quot; ] || GDB_SETUP=&quot;/tmp/gdb.setup&quot;


# Generate setup file for gdb with appropriate paths to symbols
function gdb_setup()
{
cat &lt;&lt;EOF &gt;$GDB_SETUP
  set solib-search-path $UNSTRIPPED_SO_LIB:$ANDROID_NDK/platforms/$ANDROID_TARGET/arch-arm/usr/lib
  directory $ANDROID_NDK/platforms/$ANDROID_TARGET/arch-arm/usr/include $APP_ROOT/jni $ANDROID_NDK/sources/cxx-stl/system
  ## set solib-absolute-prefix $ANDROID_NDK/platforms/$ANDROID_TARGET/arch-arm/usr/lib

  file $APP_PROCESS
  target remote :$DEBUG_PORT

  # Probably not needed. Uncomment if you have problems with watchdogs
  ## set variable gDvm.nativeDebuggerActive=true
EOF
}

# Get pid of the process (first one if there are more of them)
function get_pid_on_device()
{
    $ADB shell ps | grep &quot;$@&quot; | awk '{print $2; exit}'
}


#############################################################################
## Main entry
############################################################################


# Restart adb server. Uncomment if you have problems with adb being stuck
## $ADB kill-server

# Get the app_process and libc.so from the device
# Always download and overwrite those files to be sure we have correct ones
$ADB pull /system/bin/app_process $APP_PROCESS
$ADB pull /system/lib/libc.so $APP_LIBC_SO

# Set up port forwarding for gdb and gdbserver
if $ADB forward tcp:$DEBUG_PORT tcp:$DEBUG_PORT
then :
else
    echo Failed to setup tcp forwarding for port $DEBUG_PORT
    echo Is the device running?
    exit 1
fi

# Get pid of the process
APP_PID=`get_pid_on_device &quot;$APP_PACKAGE&quot;`
if [ -z $APP_PID ]
then
    echo &quot;$APP_PACKAGE is not running&quot;
    exit 1
fi

# Kill any prior gdbserver
GDBSERV_PID=`get_pid_on_device gdbserver`
if [ -n &quot;$GDBSERV_PID&quot; ]
then 
    $ADB shell kill $GDBSERV_PID
    sleep 1
fi

# Start gdbserver and attach it to our application
$ADB shell gdbserver :$DEBUG_PORT --attach $APP_PID &amp;
sleep 2

# Invoke gdb and feed it with setup commands to set up path to libraries
gdb_setup
$GDB_CMD -x $GDB_SETUP
rm -f $GDB_SETUP
</pre></p>
<p><strong>Have fun!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhandroid.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhandroid.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhandroid.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=21&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhandroid.wordpress.com/2011/01/25/multithread-cc-debugging-on-emulators-and-rooted-devices-from-android-1-5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/024bd611c1757a2c96f4f1a0e335507a?s=96&#38;d=wavatar&#38;r=X" medium="image">
			<media:title type="html">mhandroid</media:title>
		</media:content>
	</item>
		<item>
		<title>How C/C++ Debugging Works on Android</title>
		<link>http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/</link>
		<comments>http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 16:11:52 +0000</pubDate>
		<dc:creator>MartinH</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://mhandroid.wordpress.com/?p=12</guid>
		<description><![CDATA[How debugging of C/C++ code works on Android? Nothing special actually. Gdb itself has a feature for remote debugging. Note: For this article I am using Android NDK, r5. The behavior of ndk-build and ndk-gdb commands can be different in &#8230; <a href="http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=12&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>How debugging of C/C++ code works on Android? Nothing special actually. <em>Gdb</em> itself has a feature for remote debugging.</p>
<p><span id="more-12"></span></p>
<p>Note: For this article I am using Android NDK, r5. The behavior of <em>ndk-build</em> and <em>ndk-gdb</em> commands can be different in other versions.</p>
<p><strong>Basic setup</strong></p>
<p>You simply run <em>gdbserver</em> on the device and let it attach to some process. <em>Gdbserver</em> acts as a remote debugger which is commanded by <em>gdb</em> itself. This step is pretty easy and is done by some variant of</p>
<p><code>gdbserver :5039 --attach 123</code></p>
<p>where <em>5039</em> is a TCP port number to which <em>gdb</em> will connect and <em>123</em> is a <em>PID</em> of process we want to debug.</p>
<p>The next step is to run <em>gdb</em> client and connect it to the <em>gdbserver</em> on the device. You need to start <em>gdb</em> with command</p>
<p><code>gdb app_process</code></p>
<p>where <em>app_process</em> is Android binary which you need to copy from Android device to your PC. This binary is some kind of loader and lies in <em>/system/bin/app_process</em> file on the device (or in the emulator).</p>
<p>After you start <em>gdb</em> you connect it with the <em>gdbserver</em> by this command (ran from gdb shell)</p>
<p><code>target remote :5039</code></p>
<p>Because you are usually running Android device connected through USB and not normal TCP/IP network (or you are running Android emulator) you have to set up TCP port forwarding in advance. This is done by command</p>
<p><code>adb forward tcp:5039 tcp:5039</code></p>
<p>which you have to execute before starting <em>gdb</em>. This command will handle all connection requests to port 5039 on PC to the device on the same port.</p>
<p>And this is all.</p>
<p><strong>Debug symbols</strong></p>
<p>You typically compile your .so library with debug symbols. But it makes good sense to strip those symbols off before uploading your binary to the Android device. Binary will be smaller (which means faster installation time of the apk package), will occupy less memory and will run faster. So you upload stripped version of your libraries to the Android device and keep unstripped versions on your PC.</p>
<p>To tell <em>gdb</em> the path to the unstripped libraries run this command from gdb shell</p>
<p><code>set solib-search-path obj/local/armeabi</code></p>
<p>You can enter more paths and separate them by colon (:) character.</p>
<p>There is a difference between debug symbols and code optimization. Code optimization allows changing the code flow or removing some dead-code and unused variables. While debug symbols bind machine code together with appropriate lines in the source code. Usually you build a binary with debug symbols and no code optimization for debugging and another binary without debug symbols and with some code optimization for release. But you can use debug symbols together with code optimization. In this case some variables will be missing and some lines of code will be probably jumped over but in general you can debug this way.</p>
<p>Android <em>ndk-build</em> command always produce binaries (your lib<em>native</em>.so files) with debug symbols and place them in <em>obj/local/armeabi</em> subdirectory of your project. Then it strips off debug symbols and place stripped version in the final .apk (and thus in the device). <em>ndk-gdb</em> script uses this <em>set solib-search-path</em> command to point <em>gdb</em> to the unstripped binary so you can see your position in the source code. You can find the <em>set solib-search-path</em> command in <em>obj/local/armeabi/gdb.setup</em> file.</p>
<p>If you have <em>android:debuggable=&#8221;true&#8221;</em> in your <em>AndroidManifest.xml</em> or if you run <em>ndk-build</em> with <em>NDK_DEBUG=1</em> argument then <em>ndk-build</em> will produce binaries with no code optimization. Otherwise code optimization will be used.</p>
<p><strong>Sources</strong></p>
<p>Gdb needs to have access to your source files. Otherwise it cannot show you the source code as it is executed. You can configure directory with your source files by command</p>
<p><code>directory jni</code></p>
<p>You can enter more paths and separate them by space. Take a look into <em>obj/local/armeabi/gdb.setup</em> file for example.</p>
<p><strong>How <em>ndk-gdb</em> and friends works</strong></p>
<p>If you are using Android NDK, r5 and Android 2.3 device you can use <em>ndk-gdb</em> script which does everything for you.</p>
<p>If you have <em>android:debuggable=&#8221;true&#8221;</em> in your <em>AndroidManifest.xml</em> then <em>ndk-build</em> will add the <em>gdbserver</em> into your .apk package. This <em>gdbserver</em> will be started by <em>ndk-gdb</em> and also all the other steps will be set up by this script.</p>
<p><strong>Important caveat</strong></p>
<p>Because <em>gdbserver</em> is attached to the already running process (as opposed to situation where process would be started by <em>gdbserver</em>) it can miss some code execution which take place soon after the application start. There is no easy solution to this.</p>
<p>I usually write some endless while loop and then change the control variable after <em>gdb</em> is fully started. For example</p>
<p><pre class="brush: cpp;">
int i = 0
while (!i) {
  a++;
}
</pre></p>
<p>After <em>ndk-gdb</em> starts <em>gdb</em> session I can set breakpoints appropriately and change value of <em>i</em> variable by command</p>
<p><code>set var i=1</code></p>
<p>and then continue in application execution by <em>gdb</em> command <em>c</em>.</p>
<p><strong>Multithread debug problem</strong></p>
<p>It is well-known problem that <em>ndk-gdb</em> shipped with Android NDK, r4b used on Android 2.2 device was only able to hit the breakpoint on the main thread. If you set breakpoint on any other thread gdb session will crash.</p>
<p>Every time new thread is created <em>libc</em> will call <em>_thread_created_hook()</em> function (which has empty body). The purpose of this function is that <em>gdb</em> will set breakpoint on this function and thus will know that new thread was created. <em>Gdb</em> will then keep database of existing threads. Because of this <em>gdb</em> needs to have access to the <em>libc.so</em> file to figure out address of the <em>_thread_created_hook()</em> function.</p>
<p>Android NDK, r5 contains <em>ndk-gdb</em> which copies the file <em>libc.so</em> from the device (or emulator) and stores it in <em>obj/local/armeabi</em> subdirectory of your project. Also <em>gdbserver</em> included in this ndk is compiled with <em>libthread_db</em> support. Both those two things are missing in Android NDK, r4b.</p>
<p><strong>Links</strong></p>
<p>Description of multithreading debug bug.<br />
<a href="http://code.google.com/p/android/issues/detail?id=9713">http://code.google.com/p/android/issues/detail?id=9713</a></p>
<p>Android NDK, r5<br />
<a href="http://dl.google.com/android/ndk/android-ndk-r5-linux-x86.tar.bz2">http://dl.google.com/android/ndk/android-ndk-r5-linux-x86.tar.bz2</a></p>
<p>Android ndk main page<br />
<a href="http://developer.android.com/sdk/ndk/index.html">http://developer.android.com/sdk/ndk/index.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhandroid.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhandroid.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhandroid.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=12&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhandroid.wordpress.com/2011/01/25/how-cc-debugging-works-on-android/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/024bd611c1757a2c96f4f1a0e335507a?s=96&#38;d=wavatar&#38;r=X" medium="image">
			<media:title type="html">mhandroid</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Eclipse for Android C/C++ Debugging</title>
		<link>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/</link>
		<comments>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 11:29:24 +0000</pubDate>
		<dc:creator>MartinH</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://mhandroid.wordpress.com/?p=23</guid>
		<description><![CDATA[Yes. You can use Eclipse for debugging of C/C++ code. I personally prefer cgdb but if you want to debug in Eclipse here is how. See my&#160;previous spot how to set up cgdb debugger if you think it will suit &#8230; <a href="http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=23&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yes. You can use Eclipse for debugging of C/C++ code. I personally prefer <em>cgdb</em> but if you want to debug in Eclipse here is how.</p>
<p><span id="more-23"></span></p>
<p>See my&nbsp;<a title="Using cgdb with ndk-debug (and cgdb&nbsp;tutorial)" href="http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/">previous spot</a> how to set up <em>cgdb</em> debugger if you think it will suit you.</p>
<p>See my <a title="Using Eclipse for Android C/C++&nbsp;Development" href="http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/">blog spot</a> how to set up Eclipse for compiling and editing C/C++ code.</p>
<p><strong>0) Prerequisities</strong></p>
<p>You need Eclipse with CDT installed.<br />
See <a title="Using Eclipse for Android C/C++&nbsp;Development" href="http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/">my previous spot</a> how to do it.</p>
<p>You also need Android ndk. Download it from&nbsp;<a rel="noreferrer" href="http://developer.android.com/sdk/ndk/index.html">http://developer.android.com/sdk/ndk/index.html</a> and unpack it somewhere.</p>
<p><strong>1) In Eclipse open your Android project which contains C/C++ code that you want to debug.</strong></p>
<p>For this tutorial I’ve created simple MyAndroidProject.</p>
<p><strong>2) Set android:debuggable=&#8221;true&#8221;. Set android:targetSdkVersion=&#8221;9&#8243;. </strong></p>
<p><em>android:debuggable</em> is&nbsp;a property of&nbsp;<em>&lt;application&gt;</em> tag in your&nbsp;<em>AndroidManifest.xml</em>. You can set it either directly in xml or in <em>Application</em> tab as in the screenshot.</p>
<p><strong> </strong><a href="http://mhandroid.files.wordpress.com/2011/01/12.png"><img class="alignnone size-full wp-image-152" title="Set android:debuggable=&quot;true&quot;" src="http://mhandroid.files.wordpress.com/2011/01/12.png?w=640&#038;h=448" alt="" width="640" height="448" /></a></p>
<p><em>android:targetSdkVersion=&#8221;9&#8243;</em> is a property of <em>&lt;uses-sdk&gt;</em> tag&nbsp;in your&nbsp;<em>AndroidManifest.xml</em>. You can set it either directly in xml or in&nbsp;<em>Manifest</em> tab as in the screenshot.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/41.png"><img class="alignnone size-full wp-image-157" title="Set android:targetSdkVersion=&quot;9&quot;" src="http://mhandroid.files.wordpress.com/2011/01/41.png?w=640&#038;h=448" alt="" width="640" height="448" /></a></p>
<p><strong>3) Run your application in debug mode and try to run <em>ndk-gdb</em> from console</strong></p>
<p>To run application in debug mode press debug button (green bug/spider button in toolbox). In console go to your project directory and run <em>ndk-gdb</em>. It should succeed. If it fails you have to resolve the problem. Running <em>ndk-gdb</em> does not only ensure us that we are doing everything right so far, but also creates <em>app_process</em>, <em>gdb.setup</em> and<em> libc.so</em> files in <em>obj/local/armeabi/</em> subdirectory of our project. Those files will be needed in later steps.</p>
<p><strong>4) Create C/C++ debug configuration</strong></p>
<p>Click on combo-box like down arrow next to debug button. Pop-up menu will appear and then select <em>Debug Configurations&#8230;</em></p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/21.png"><img class="alignnone size-full wp-image-156" title="Select Debug Configurations... in Debug button pop-up" src="http://mhandroid.files.wordpress.com/2011/01/21.png?w=640&#038;h=448" alt="" width="640" height="448" /></a></p>
<p>In <em>Debug Configurations</em> window select <em>C/C++ Application</em> and press <em>New</em> button as advised on the right pane.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/31.png"><img class="alignnone size-full wp-image-160" title="Create new C/C++ debug configuration" src="http://mhandroid.files.wordpress.com/2011/01/31.png?w=640&#038;h=476" alt="" width="640" height="476" /></a></p>
<p><strong>5) Set <em>name</em> of the debug configuration, and fill information on <em>Main</em> tab.</strong></p>
<p>Select <em>Standard Create Process Launcher</em> by clicking on the blue&nbsp;<em>Select other&#8230;</em> link at the bottom of the window.</p>
<p>In <em>C/C++ Application</em> entry fill the path to the <em>app_process</em> binary which is located in <em>obj/local/armeabi/</em> subdirectory of your project.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/51.png"><img class="alignnone size-full wp-image-163" title="Fill Main tab with information about C/C++ debug configuration" src="http://mhandroid.files.wordpress.com/2011/01/51.png?w=640&#038;h=414" alt="" width="640" height="414" /></a></p>
<p><strong>6) Click on <em>Debugger</em> tab and fill information about debugger.</strong></p>
<p>Choose <em>gdbserver Debugger</em> as a Debugger.</p>
<p>It&#8217;s good idea to set initial breakpoint to some function but Android projects do not contain <em>main</em> function so fill some appropriate function name in <em>Stop on startup</em> field (I filled&nbsp;<em>Java_com_example_map_MyAndroidProject_doSomething</em> but you can see only&nbsp;<em>Java_com_exam</em> on the screenshot).</p>
<p>Set path to <em>GDB debugger</em>. The debugger is distributed with the Android ndk. Its located at <em>toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb</em>.</p>
<p>Set path to <em>GDB command line</em>. This path should point to&nbsp;<em>obj/local/armeabi/gdb2.setup</em> file inside your project. You don&#8217;t have <em>gdb2.setup</em> file there yet but you will create one in a while.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/61.png"><img class="alignnone size-full wp-image-164" title="Fill Debugger-&gt;Main with information about debugger" src="http://mhandroid.files.wordpress.com/2011/01/61.png?w=640&#038;h=312" alt="" width="640" height="312" /></a></p>
<p><strong>7) Click on the <em>Connection</em> tab (so you are in <em>Debugger-&gt;Connection</em> section of your C/C++ debug configuration) and fill information about connecting <em>gdb</em> with <em>gdbserver</em>.</strong></p>
<p>Choose <em>TCP</em> as a type of connection and choose <em>5039</em> as a <em>Port number</em>.</p>
<p><strong><a href="http://mhandroid.files.wordpress.com/2011/01/71.png"><img class="alignnone size-full wp-image-165" title="Fill Debugger-&gt;Connection with information about connection" src="http://mhandroid.files.wordpress.com/2011/01/71.png?w=640&#038;h=312" alt="" width="640" height="312" /></a></strong></p>
<p><strong>8) Finally click <em>Apply</em> to save all the information about your C/C++ debug configuration.</strong></p>
<p>This will save your new C/C++ debug configuration. Later, when running your application in debug mode you can choose in combo box associated with Debug button what debug configuration you want to use.&nbsp;Now you have two debug configurations. Android Java one which was created automatically for you when you&#8217;ve created Android project. And C/C++ one you&#8217;ve just created.</p>
<p><strong>9) Go to the&nbsp;<em>obj/local/armeabi/</em> subdirectory of your project and copy <em>gdb.setup</em> file to <em>gdb2.setup</em> file. Remove&nbsp;<em>target remote :5039</em> line from <em>gdb2.setup</em>.</strong></p>
<p>Eclipse don&#8217;t like&nbsp;<em>target remote :5039</em> line in gdb setup file because it wants to enter this command internally (that is why you configured port 5039 in the previous step). Because the <em>gdb.setup</em> file is recreated by ndk scripts you have to copy it to the&nbsp;<em>gdb2.setup</em> and point Eclipse to the <em>gdb2.setup</em> file (we did this in step 6).</p>
<p><strong>10) Go to the directory with Android ndk and copy <em>ndk-gdb</em> to <em>ndk-gdb-eclipse</em>. Remove execution of gdb command from <em>ndk-gdb-eclipse</em>.</strong></p>
<p>Original content of ndk-gdb (Android NDK, r5):</p>
<p><pre class="brush: bash; first-line: 578;">
if [ -n &quot;$OPTION_EXEC&quot; ] ; then
    cat $OPTION_EXEC &gt;&gt; $GDBSETUP
fi
$GDBCLIENT -x `native_path $GDBSETUP`
</pre></p>
<p><em> </em><br />
Content of ndk-gdb-eclipse:</p>
<p><pre class="brush: bash; first-line: 578;">
if [ -n &quot;$OPTION_EXEC&quot; ] ; then
    cat $OPTION_EXEC &gt;&gt; $GDBSETUP
fi
## $GDBCLIENT -x `native_path $GDBSETUP`
</pre></p>
<p>Eclipse will run the <em>gdb</em> binary itself. So we have to remove the execution of <em>gdb</em> from<em> ndk-gdb</em>. To save original content it is good idea to copy the <em>ndk-gdb</em> to <em>ndk-gdb-eclipse</em>.</p>
<p><strong>11) Now you are done. Put breakpoint in Java code after the execution of <em>System.loadLibrary()</em> and start your application in Debug mode.</strong></p>
<p>Start your application in debug mode by clicking on Debug button. It will automatically choose Android debug mode. Later you will have to take care to choose Android Java debugging configuration by clicking on combo arrow associated with the debug button.</p>
<p>The reason that breakpoint should be after <em>System.loadLibrary()</em> call is that our C/C++ code will be already loaded in that point and we can set breakpoints in it.</p>
<p><strong>12) When execution reach the breakpoint run <em>ndk-gdb-eclipse</em> from your project directory and start debugging in C/C++ debug mode.</strong></p>
<p>Go to the directory with your project and run <em>ndk-gdb-eclipse</em>. This will start server-part of the debugging infrastructure. Now click on the combo arrow associated with the debug button in Eclipse and choose <em>Debug Configurations&#8230;</em> Choose your C/C++ debug configuration and click <em>Debug</em> button.</p>
<p>The C/C++ debug configuration will be added to recently used debug configurations so later you don&#8217;t have to walk into the <em>Debug Configurations&#8230;</em> window again and you can choose between Android Java debug configuration and C/C++ debug configuration by just clicking on the combo arrow associated with debug button in Eclipse. However always make sure which debug configuration you are about to execute as this is where mistakes happen very often (at least for me).</p>
<p>After you&#8217;ve started C/C++ debug configuration click <em>Resume</em> button (or press F8). The application should resume its run and stop on C/C++ breakpoint (if you have one).</p>
<p><strong>13) Now you are debugging the C/C++ code. Have fun!</strong></p>
<p>Try to set some breakpoints in C/C++ code, etc.</p>
<p><strong>Note on running <em>ndk-gdb-eclipse</em></strong></p>
<p>You have to run <em>ndk-gdb-eclipse</em> every time before starting C/C++ debug session. This script starts the <em>gdbserver</em> binary on device/emulator so gdb (run by Eclipse) can connect to it.</p>
<p>I made several attempts to force Eclipse to run <em>ndk-gdb-eclipse</em> script itself on start of C/C++ debug session. The most logical point is to write small script which will run <em>ndk-gdb-eclipse</em> without parameters (or with <em>&#8211;force</em> parameter) and then run <em>gdb</em> from Android ndk toolchain with all the parameters. This script can be used as <em>GDB debugger</em> command in the <em>Debugger</em> tab. But even if this script (and <em>ndk-gdb-eclipse</em> inside) was run successfully, the resulting connection of gdb and gdbserver always broke apart.</p>
<p><strong>Final note and thanks!</strong></p>
<p>This tutorial is heavily inspired by Sequoyah Project native debug tutorial.&nbsp;See&nbsp;<a href="http://www.eclipse.org/sequoyah/documentation/native_debug.php">http://www.eclipse.org/sequoyah/documentation/native_debug.php</a></p>
<p>Many thanks to you guys.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhandroid.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhandroid.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhandroid.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=23&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/024bd611c1757a2c96f4f1a0e335507a?s=96&#38;d=wavatar&#38;r=X" medium="image">
			<media:title type="html">mhandroid</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/12.png" medium="image">
			<media:title type="html">Set android:debuggable=&#34;true&#34;</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/41.png" medium="image">
			<media:title type="html">Set android:targetSdkVersion=&#34;9&#34;</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/21.png" medium="image">
			<media:title type="html">Select Debug Configurations... in Debug button pop-up</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/31.png" medium="image">
			<media:title type="html">Create new C/C++ debug configuration</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/51.png" medium="image">
			<media:title type="html">Fill Main tab with information about C/C++ debug configuration</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/61.png" medium="image">
			<media:title type="html">Fill Debugger-&#62;Main with information about debugger</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/71.png" medium="image">
			<media:title type="html">Fill Debugger-&#62;Connection with information about connection</media:title>
		</media:content>
	</item>
		<item>
		<title>Using cgdb with ndk-debug (and cgdb tutorial)</title>
		<link>http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/</link>
		<comments>http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 11:24:00 +0000</pubDate>
		<dc:creator>MartinH</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[cgdb]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://mhandroid.wordpress.com/?p=14</guid>
		<description><![CDATA[Android ndk (http://developer.android.com/sdk/ndk/index.html) comes with ndk-gdb command that starts gdb debugger and connects it to Android application. cgdb (http://cgdb.sourceforge.net/) is superior console front-end to gdb so it seems logical to use it for debugging of Android applications. Following modification of &#8230; <a href="http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=14&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Android ndk (<a href="http://developer.android.com/sdk/ndk/index.html">http://developer.android.com/sdk/ndk/index.html</a>) comes with <em>ndk-gdb</em> command that starts <em>gdb</em> debugger and connects it to Android application.</p>
<p><em>cgdb</em> (<a href="http://cgdb.sourceforge.net/">http://cgdb.sourceforge.net/</a>) is superior console front-end to <em>gdb s</em>o it seems logical to use it for debugging of Android applications. Following modification of <em>ndk-gdb</em> script will cause that <em>cgdb</em> will be invoked instead of <em>gdb</em>.</p>
<p><span id="more-14"></span></p>
<p>Original <em>ndk-gdb</em> (Android NDK, r5):</p>
<p><pre class="brush: bash; first-line: 569;">
# Now launch the appropriate gdb client with the right init commands
#
GDBCLIENT=${TOOLCHAIN_PREFIX}gdb
GDBSETUP=$APP_OUT/gdb.setup
</pre></p>
<p><em> </em><br />
Modified <em>ndk-gdb</em> (originally from Android NDK, r5) which uses cgdb instead of gdb:</p>
<p><pre class="brush: bash; first-line: 569;">
# Now launch the appropriate gdb client with the right init commands
#
GDBCLIENT=&quot;cgdb -d ${TOOLCHAIN_PREFIX}gdb --&quot;
GDBSETUP=$APP_OUT/gdb.setup
</pre></p>
<p><em> </em><br />
Now if you run ndk-gdb you will get <em>cgdb</em> front-end.<br />
<a href="http://mhandroid.files.wordpress.com/2011/01/11.png"><img class="alignnone size-full wp-image-104" title="cgdb debugging simple Android application" src="http://mhandroid.files.wordpress.com/2011/01/11.png?w=640&#038;h=436" alt="" width="640" height="436" /></a></p>
<h3>Small cgdb tutorial</h3>
<p>In <em>cgdb</em> you can have focus either on <em>source</em> window (part with the source text) or <em>gdb</em> window.<br />
To switch from <em>source</em> window to <em>gdb</em> <strong>press i</strong>.<br />
To switch from <em>gdb</em> window to <em>source</em> <strong>press esc</strong>.</p>
<p>Commands you can use in <strong>source</strong> window:<br />
<strong>arrows</strong> &#8212; scroll the text<br />
<strong>space</strong> &#8212; set or delete breakpoint<br />
<strong>o</strong> &#8212; open source file<br />
<strong>i</strong> &#8212; switch focus to gdb window<br />
<strong>-</strong> &#8212; make source window 1 line smaller<br />
<strong>=</strong> &#8212; make source window 1 line bigger</p>
<p>Commands you can use in <strong>gdb</strong> window:<br />
<strong>n</strong> &#8212; next instruction. Will not dive into subfunctions<br />
<strong>s</strong> &#8212; step. Will dive into subfunctions<br />
<strong>c</strong> &#8212; continue<br />
<strong>b</strong> &#8212; set breakpoint<br />
<strong>bt</strong> &#8212; show call stack (backtrace)<br />
<strong>info threads</strong> &#8212; show information about running threads<br />
<strong>info breakpoints</strong> &#8212; show information about breakpoints<br />
<strong>pgup, pgdown</strong> &#8212; scroll the content of gdb window<br />
<strong>esc</strong> &#8212; switch focus to source windows</p>
<p>Full <em>cgdb</em> documentation is at&nbsp;<a href="http://cgdb.sourceforge.net/docs/cgdb-no-split.html">http://cgdb.sourceforge.net/docs/cgdb-no-split.html</a><br />
Full <em>gdb</em> documentation is at&nbsp;<a href="http://www.gnu.org/software/gdb/documentation/">http://www.gnu.org/software/gdb/documentation/</a></p>
<p>Have fun!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhandroid.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhandroid.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhandroid.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=14&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhandroid.wordpress.com/2011/01/23/using-cgdb-with-ndk-debug-and-cgdb-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/024bd611c1757a2c96f4f1a0e335507a?s=96&#38;d=wavatar&#38;r=X" medium="image">
			<media:title type="html">mhandroid</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/11.png" medium="image">
			<media:title type="html">cgdb debugging simple Android application</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Eclipse for Android C/C++ Development</title>
		<link>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/</link>
		<comments>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 11:21:11 +0000</pubDate>
		<dc:creator>MartinH</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://mhandroid.wordpress.com/?p=10</guid>
		<description><![CDATA[Programming in C/C++ on Android is just awesome! This tutorial shows how to setup Eclipse for using C/C++ together with Java in Android projects. 0) Prerequisities You need to have Google ADT (Android Development Tools) installed. See&#160;http://developer.android.com/sdk/eclipse-adt.html how to do &#8230; <a href="http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=10&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Programming in C/C++ on Android is just awesome! This tutorial shows how to setup Eclipse for using C/C++ together with Java in Android projects.</p>
<p><span id="more-10"></span></p>
<p><strong>0) Prerequisities</strong></p>
<p>You need to have Google ADT (Android Development Tools) installed. See&nbsp;<a href="http://developer.android.com/sdk/eclipse-adt.html">http://developer.android.com/sdk/eclipse-adt.html</a> how to do it.</p>
<p>You also need Android ndk. Download it from&nbsp;<a href="http://developer.android.com/sdk/ndk/index.html">http://developer.android.com/sdk/ndk/index.html</a> and unpack it somewhere.</p>
<p><strong>1) Install CDT (C/C++ Development Tools) into Eclipse.</strong></p>
<p>Choose <em>Help-&gt;Install New Software&#8230;</em> from the main menu.</p>
<p>Choose <em>http://download.eclipse.org/releases/galileo</em> as the source site. If you have another Eclipse release than Galileo choose the appropriate url.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/1.png"><img title="Install C/C++ Development Tools" src="http://mhandroid.files.wordpress.com/2011/01/1.png?w=640&#038;h=497" alt="" width="640" height="497" /></a></p>
<p>Click <em>Next</em>, Accept licences and finish the installation process.</p>
<p><strong>2) In Eclipse create Android project to which you want to add C/C++ code (if you already don&#8217;t have one).</strong></p>
<p>For this tutorial I&#8217;ve created simple MyAndroidProject.</p>
<p><strong>3) In file manager create <em>jni/</em> directory in your project directory and place your C/C++ sources file here. Also put here <em>Android.mk</em> file which is a makefile that tells Android build-system how to build your files.</strong></p>
<p>Take a look into Android ndk <em>docs/ANDROID-MK.html</em> file how to create one.</p>
<p>Simple example of <em>Android.mk</em> file:</p>
<p><pre class="brush: plain;">
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_LDLIBS    := -llog

LOCAL_MODULE    := native
LOCAL_SRC_FILES := native.c

include $(BUILD_SHARED_LIBRARY)
</pre></p>
<p><strong>4) &nbsp;Refresh (F5) directories in <em>Package Explorer</em> to see <em>jni</em> directory here. Open your .c/.cpp file.</strong></p>
<p>Your .c/.cpp file (<em>native.c</em> in my case) contains a lot of syntax errors which are not truly syntax errors. This is because Eclipse threats the project as a pure Java project. We have to convert the project into mixed Java &amp; C/C++ project.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/2.png"><img class="alignnone size-full wp-image-56" title="C/C++ file just added to our project" src="http://mhandroid.files.wordpress.com/2011/01/2.png?w=640&#038;h=457" alt="" width="640" height="457" /></a></p>
<p><strong>5) Press <em>Ctrl+n</em> (or choose <em>File-&gt;New-&gt;Other&#8230;</em> from main menu) and select <em>Convert to a C/C++ Project</em>.</strong></p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/3.png"><img class="alignnone size-full wp-image-57" title="Convert to a C/C++ Project" src="http://mhandroid.files.wordpress.com/2011/01/3.png?w=640" alt=""   /></a></p>
<p>This will convert your project into a mixed Java &amp; C/C++ project rather than into pure C/C++ project (the name of the function is misleading).</p>
<p>Click <em>Next</em>. Then choose your project and below choose <em>Makefile project</em> and <em>&#8211; Other Toolchain &#8211;</em>. Click <em>Finish</em>.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/4.png"><img class="alignnone size-full wp-image-58" title="Convert to C/C++ Project Window" src="http://mhandroid.files.wordpress.com/2011/01/4.png?w=640" alt=""   /></a></p>
<p>After doing this Eclipse will ask you if you want to switch to C/C++ perspective. Choose <em>Yes</em> because otherwise you wouldn&#8217;t be able to set C/C++ build preferences.</p>
<p><strong>6) Click on your project with right button and select <em>Properties</em> or press Alt+Enter</strong></p>
<p>Properties windows will appear. Here you have to configure use of ndk-build instead of make all command and set proper include paths.</p>
<p><strong>7) Choose <em>C/C++ Build</em> and configure <em>ndk-build</em> as a build command</strong></p>
<p>In <em>Builder settings</em> fill <em>ndk-build</em> into <em>Build command</em> entry.&nbsp;You have to uncheck <em>Use default build command</em>. You also need to have ndk-build script in your PATH.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/5.png"><img class="alignnone size-full wp-image-59" title="Set ndk-build as a build tool" src="http://mhandroid.files.wordpress.com/2011/01/5.png?w=640&#038;h=437" alt="" width="640" height="437" /></a></p>
<p>In <em>Behaviour</em> setting uncheck <em>clean</em> (ndk-build cleans project automatically on build and does not support separate clean command) and clear all text from build (<em>ndk-build</em> does not accept <em>all</em> as a parameter.</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/6.png"><img class="alignnone size-full wp-image-60" title="Configure ndk-build parameters and usage" src="http://mhandroid.files.wordpress.com/2011/01/6.png?w=640&#038;h=437" alt="" width="640" height="437" /></a></p>
<p>Click <em>Apply</em> to save settings.</p>
<p><strong>8) Choose <em>C/C++ General-&gt;Paths and Symbols</em> and configure include path</strong></p>
<p>In <em>Includes</em> tab choose <em>GNU C</em> or <em>GNU C++</em> and click <em>Add&#8230;</em> button. Add path to include directory which is located in <em>platforms/android-4/arch/arm/usr/include</em> subdirectory of place where you&#8217;ve unpacked Android ndk. Include path depends on target for which you are compiling (<em>android-4</em> in my case &#8212; i.e. Android 1.6).</p>
<p><a href="http://mhandroid.files.wordpress.com/2011/01/7.png"><img class="alignnone size-full wp-image-61" title="Configure include path" src="http://mhandroid.files.wordpress.com/2011/01/7.png?w=640&#038;h=322" alt="" width="640" height="322" /></a></p>
<p>Finally click <em>Apply</em> and <em>OK</em> and that is all. Now you can use all Eclipse power for editing your C/C++ sources. If you click <em>Run</em> or <em>Debug</em> Eclipse will compile C/C++ code as well as Java code and run it on device/emulator. However you will not be able to debug C/C++ code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mhandroid.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mhandroid.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mhandroid.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mhandroid.wordpress.com&amp;blog=17868283&amp;post=10&amp;subd=mhandroid&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/024bd611c1757a2c96f4f1a0e335507a?s=96&#38;d=wavatar&#38;r=X" medium="image">
			<media:title type="html">mhandroid</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/1.png" medium="image">
			<media:title type="html">Install C/C++ Development Tools</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/2.png" medium="image">
			<media:title type="html">C/C++ file just added to our project</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/3.png" medium="image">
			<media:title type="html">Convert to a C/C++ Project</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/4.png" medium="image">
			<media:title type="html">Convert to C/C++ Project Window</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/5.png" medium="image">
			<media:title type="html">Set ndk-build as a build tool</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/6.png" medium="image">
			<media:title type="html">Configure ndk-build parameters and usage</media:title>
		</media:content>

		<media:content url="http://mhandroid.files.wordpress.com/2011/01/7.png" medium="image">
			<media:title type="html">Configure include path</media:title>
		</media:content>
	</item>
	</channel>
</rss>
