blob: 3f1b7f05e4b22e51887e78030ffeee147b671bc3 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.5"/>
<title>NDK Programmer&#39;s Guide: Main Page</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">Native Development Kit ("NDK")
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.5 -->
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Getting Started with the NDK</div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This document explains how to:</p>
<ul>
<li><a href=#install>Get and install the NDK.</a></li>
<li><a href=#configure>Configure your system and the Eclipse and the Android Development Tools (“ADT”) for use with it.</a></li>
<li><a href=#verify>Verify, using a simple sample, that everything is working as expected.</a></li>
</ul>
<p>Note that this document assumes that you are already familiar with Java-based Android development. For more information on that topic, see the <a href="http://developer.android.com">Android developer site</a>.</p>
<a id=install></a>
<h2>Installation</h2>
<p>To install and configure the NDK, follow the steps below:
<ol type="1">
<li>To use the NDK, you must first have the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> installed.</li>
<li>Next, <a href="http://developer.android.com/tools/sdk/ndk/index.html">download</a> and unzip the NDK, making sure to download the correct version for your development platform. You may place the unzipped directory anywhere on your local drive.</li>
<li><b>If you are building from the command line,</b> open a terminal window, and update your <code>PATH</code> environment variable with the location of the directory that contains the NDK.</li>
</ol>
<ul style="list-style: none; ">
<li>
<p class="startli">For example, in bash:</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"></p>
<pre class="fragment">export PATH=$PATH:~/Android_SDK/NDK/<android-ndk-version>
</pre><p class="endli"></p>
</li>
<li>
<p class="startli">Or, in Windows:</p>
<p class="endli"></p>
</li>
<li>
<p class="startli"></p>
<pre class="fragment">set PATH=%PATH%;C:/Android_SDK/NDK/android-ndk-r10
</pre> </li>
</ul>
<a id=configure></a>
<h2>Configuring Eclipse</h2>
<p>Eclipse must know where the NDK is in order to use it when building your app.Follow these steps to set the location of the NDK:</p>
<ol type="1">
<li>Launch Eclipse, which is installed as part of the Android SDK.</li>
<li>Open <b>Preferences</b>.</li>
<li>In the pane on the left side of the <em>Preferences</em> window, select <strong>Android &gt; NDK</strong>. The <em>Android</em> section expands, revealing a number of subsections.</li>
<li>Select <b>NDK</b>. In the pane on the right side of the <em>Preferences</em> window, browse to the directory that contains the NDK.
<li>Click <b>OK</b> to return to the <em>Package Explorer</em> display.</li>
</ol>
<a id=verify></a>
<h2>Verification</h2>
<h3>Eclipse</h3>
<p> To confirm that you have installed the NDK, set it up correctly, and properly configure Eclipse, follow these steps:</p>
<ol type="1">
<li>Import the hello-jni sample from `&lt;ndk&gt;/samples/’, as you would any other Android project.</li>
<li>In the <em>Project Explorer</em> pane, right-click the project name (<em>HelloJni</em>). A context menu appears.</li>
<li>From the context menu, select <b>Android Tools</b> &gt; <b>Add Native Support</b>, as shown in Figure 2. The <em>Add Android Native Support</em> window appears.</li>
<div class="image">
<img src="./images/Figure_2.png" alt="Adding native support" align="left" width="660"/>
</div>
<p style="clear:both"><b>Figure 1.</b> Adding native support to your project</p>
<li>Accept the default library name (“hello-jni”), and click <b>Finish</b>.</li>
<li>Build and execute the application.</li>
</ol>
<h3>Command line</h3>
Follow these steps to build from the command line:
<ol type="1">
<li>Change to the root directory of your project.</li>
<li>Execute ndk-build to build the native component of your app.<br/>
</li>
<pre class="fragment">$ ndk-build
</pre>
</code></p>
<li>Build and install your project as you would a regular Android app written in Java. For more information, see <a href="http://developer.android.com/tools/building/index.html">Building and Running</a> and <a href="http://developer.android.com/tools/building/building-cmdline.html">Building and Running from the Command Line</a>.</li>
</ol>
<p>If you have successfully installed and configured the NDK, the screen on your target device looks as shown in Figure 3.</p>
<div class="image">
<img src="./images/Figure_3.png" alt="successful launch screen" align="left" width="220"/>
</div>
<p style="clear:both"><b>Figure 2.</b> Target-device screen after successful launch </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Jun 16 2014 21:28:06 for Native Development Kit ("NDK") by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.5
</small></address>
</body>
</html>