1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6<meta name="generator" content="Doxygen 1.8.5"/>
7<title>NDK Programmer&#39;s Guide: Main Page</title>
8<link href="tabs.css" rel="stylesheet" type="text/css"/>
9<script type="text/javascript" src="jquery.js"></script>
10<script type="text/javascript" src="dynsections.js"></script>
11<link href="doxygen.css" rel="stylesheet" type="text/css" />
12</head>
13<body>
14<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
15<div id="titlearea">
16<table cellspacing="0" cellpadding="0">
17 <tbody>
18 <tr style="height: 56px;">
19  <td style="padding-left: 0.5em;">
20   <div id="projectname">Native Development Kit ("NDK")
21   </div>
22  </td>
23 </tr>
24 </tbody>
25</table>
26</div>
27<!-- end header part -->
28<!-- Generated by Doxygen 1.8.5 -->
29</div><!-- top -->
30<div class="header">
31  <div class="headertitle">
32<div class="title">Getting Started with the NDK</div>  </div>
33</div><!--header-->
34<div class="contents">
35<div class="textblock"><p>This document explains how to:</p>
36<ul>
37<li><a href=#install>Get and install the NDK.</a></li>
38<li><a href=#configure>Configure your system and the Eclipse and the Android Development Tools (“ADT”) for use with it.</a></li>
39<li><a href=#verify>Verify, using a simple sample, that everything is working as expected.</a></li>
40</ul>
41<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>
42<a id=install></a>
43<h2>Installation</h2>
44<p>To install and configure the NDK, follow the steps below:
45<ol type="1">
46<li>To use the NDK, you must first have the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> installed.</li>
47<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>
48<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>
49</ol>
50<ul style="list-style: none; ">
51<li>
52<p class="startli">For example, in bash:</p>
53<p class="endli"></p>
54</li>
55<li>
56<p class="startli"></p>
57<pre class="fragment">export PATH=$PATH:~/Android_SDK/NDK/<android-ndk-version>
58</pre><p class="endli"></p>
59</li>
60<li>
61<p class="startli">Or, in Windows:</p>
62<p class="endli"></p>
63</li>
64<li>
65<p class="startli"></p>
66<pre class="fragment">set PATH=%PATH%;C:/Android_SDK/NDK/android-ndk-r10
67</pre> </li>
68</ul>
69<a id=configure></a>
70<h2>Configuring Eclipse</h2>
71<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>
72<ol type="1">
73<li>Launch Eclipse, which is installed as part of the Android SDK.</li>
74<li>Open <b>Preferences</b>.</li>
75<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>
76<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.
77
78<li>Click <b>OK</b> to return to the <em>Package Explorer</em> display.</li>
79</ol>
80<a id=verify></a>
81<h2>Verification</h2>
82<h3>Eclipse</h3>
83<p> To confirm that you have installed the NDK, set it up correctly, and properly configure Eclipse, follow these steps:</p>
84<ol type="1">
85<li>Import the hello-jni sample from `&lt;ndk&gt;/samples/’, as you would any other Android project.</li>
86<li>In the <em>Project Explorer</em> pane, right-click the project name (<em>HelloJni</em>). A context menu appears.</li>
87<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>
88
89<div class="image">
90<img src="./images/Figure_2.png"  alt="Adding native support" align="left" width="660"/>
91</div>
92<p style="clear:both"><b>Figure 1.</b> Adding native support to your project</p>
93
94<li>Accept the default library name (“hello-jni”), and click <b>Finish</b>.</li>
95<li>Build and execute the application.</li>
96</ol>
97<h3>Command line</h3>
98Follow these steps to build from the command line:
99
100<ol type="1">
101<li>Change to the root directory of your project.</li>
102<li>Execute ndk-build to build the native component of your app.<br/>
103</li>
104
105<pre class="fragment">$ ndk-build
106</pre>
107 </code></p>
108
109<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>
110</ol>
111<p>If you have successfully installed and configured the NDK, the screen on your target device looks as shown in Figure 3.</p>
112<div class="image">
113<img src="./images/Figure_3.png"  alt="successful launch screen" align="left" width="220"/>
114</div>
115<p style="clear:both"><b>Figure 2.</b> Target-device screen after successful launch </p>
116</div></div><!-- contents -->
117<!-- start footer part -->
118<hr class="footer"/><address class="footer"><small>
119Generated on Mon Jun 16 2014 21:28:06 for Native Development Kit ("NDK") by &#160;<a href="http://www.doxygen.org/index.html">
120<img class="footer" src="doxygen.png" alt="doxygen"/>
121</a> 1.8.5
122</small></address>
123</body>
124</html>
125