Home | History | Annotate | Download | only in guides
      1 page.title=Setup
      2 @jd:body
      3 
      4 
      5 <div id="qv-wrapper">
      6     <div id="qv">
      7       <h2>On this page</h2>
      8 
      9       <ol>
     10         <li><a href="#install">Installation</a></li>
     11         <li><a href="#configure">Configuring Eclipse</a></li>
     12         <li><a href="#verify">Verification</a></li>
     13           </ol>
     14         </li>
     15       </ol>
     16     </div>
     17   </div>
     18 
     19 
     20 <div class="contents">
     21 <div class="textblock"><p>This document explains how to:</p>
     22 <ul>
     23 <li><a href="#install">Get</a> and install the NDK.</li>
     24 <li><a href="#configure">Configure</a> your system and the Eclipse and the Android Development Tool
     25 (ADT) for use with it.</li>
     26 <li><a href="#verify">Verify</a>, using a simple sample, that everything is working as expected.
     27 </li>
     28 </ul>
     29 <p>This document assumes that you are already familiar with Java-based Android development. For more
     30 information on that topic, see the
     31 <a href="{@docRoot}">Android developer site</a>.</p>
     32 
     33 <h2 id="install">Installation</h2>
     34 <p>To install and configure the NDK, follow these steps:</p>
     35 <ol type="1">
     36 <li>Get and install the <a href="{@docRoot}studio/index.html">Android SDK</a>.</li>
     37 <li><a href="{@docRoot}ndk/downloads/index.html">Download</a> the NDK,
     38 making sure to download the correct version for your development platform. You may place the
     39 unzipped directory anywhere on your local drive.</li>
     40 <li>Update your {@code PATH} environment variable with the location of the directory that
     41 contains the NDK.</li>
     42 </ol>
     43 
     44 
     45 <h2 id="configure">Configuring Eclipse</h2>
     46 <p>Eclipse must know where the NDK is in order to use it when building your app. Follow these steps
     47 to set the location of the NDK.</p>
     48 <ol type="1">
     49 <li>Launch Eclipse, which is installed as part of the Android SDK.</li>
     50 <li>Open <b>Window</b> &gt; <b>Preferences</b>.</li>
     51 <li>In the pane on the left side of the <i>Preferences</i> window, select <i>Android</i>.
     52 The <i>Android</i> section expands, revealing a number of subsections.</li>
     53 <li>Select <b>NDK</b>. In the pane on the right side of the <i>Preferences</i> window, browse to
     54 the directory that contains the NDK.</li>
     55 <li>Click <b>OK</b> to return to the <i>Package Explorer</i> display.</li>
     56 </ol>
     57 
     58 <h2 id="verify">Verification</h2>
     59 <h3>Eclipse</h3>
     60 <p>To confirm that you have installed the NDK, set it up correctly, and properly configured Eclipse,
     61 follow these steps:</p>
     62 <ol type="1">
     63 <li>Import the hello-jni sample from {@code <ndk>/samples/}, as you would any other Android
     64 project.</li>
     65 <li>In the <i>Project Explorer</i> pane, right-click the project name (<i>HelloJni</i>). A
     66 context menu appears.</li>
     67 <li>From the context menu, select <b>Android Tools</b> &gt; <b>Add Native Support</b>. The
     68 <i>Add Android Native Support</i> window appears.</li>
     69 <li>Accept the default library name (hello-jni), and click <b>Finish</b>.</li>
     70 <li>Build and execute the application.</li>
     71 </ol>
     72 <h3>Command line</h3>
     73 <p>Follow these steps to build from the command line:</p>
     74 <ol type="1">
     75 <li>Change to the root directory of your project.</li>
     76 <li>Execute ndk-build to build the native component of your app. do this by
     77 typing {@code ndk-build} at the command prompt.</li>
     78 <li>Build and install your project as you would a regular Android app written in Java. For more
     79 information, see
     80 <a href="{@docRoot}tools/building/index.html">Building and Running</a> and
     81 <a href="{@docRoot}tools/building/building-cmdline.html">Building and Running
     82 from the Command Line</a>.</li>
     83 </ol>
     84 
     85 <p>If you have successfully installed and configured the NDK, the screen on your target device looks
     86 as shown in Figure 1.</p>
     87 
     88 <img src="./images/verification_screen.png" srcset="./images/verification_screen@2x.png 2x"
     89 alt="Output: Hello from JNI!" id="figure1" />
     90 
     91 <p class="img-caption">
     92 <strong>Figure 1.</strong> Target-device screen after successful launch.
     93 </p>
     94