blob: 0b441323b35bd5454a2d43389dafc185d0349283 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="Description" content="This document explains how to: This document assumes that you are already familiar with Java-based Android development. For more information on that topic, see the Android developer site . To install and configure the NDK, follow these steps: Eclipse …">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Setup | Android Developers</title>
<!-- STYLESHEETS -->
<link rel="stylesheet"
href="//fonts.googleapis.com/css?family=Roboto+Condensed">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold"
title="roboto">
<link href="/assets/css/default.css?v=5" rel="stylesheet" type="text/css">
<!-- JAVASCRIPT -->
<script src="//www.google.com/jsapi" type="text/javascript"></script>
<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script>
<script type="text/javascript">
var toRoot = "/";
var metaTags = [];
var devsite = false;
</script>
<script src="/assets/js/docs.js?v=3" type="text/javascript"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-5831155-1', 'android.com');
ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'}); // New tracker);
ga('send', 'pageview');
ga('universal.send', 'pageview'); // Send page view for new tracker.
</script>
</head>
<body class="gc-documentation develop guide" itemscope itemtype="http://schema.org/Article">
<a name="top"></a>
<!-- dialog to prompt lang pref change when loaded from hardcoded URL
<div id="langMessage" style="display:none">
<div>
<div class="lang en">
<p>You requested a page in English, would you like to proceed with this language setting?</p>
</div>
<div class="lang es">
<p>You requested a page in Spanish (Español), would you like to proceed with this language setting?</p>
</div>
<div class="lang ja">
<p>You requested a page in Japanese (日本語), would you like to proceed with this language setting?</p>
</div>
<div class="lang ko">
<p>You requested a page in Korean (한국어), would you like to proceed with this language setting?</p>
</div>
<div class="lang ru">
<p>You requested a page in Russian (Русский), would you like to proceed with this language setting?</p>
</div>
<div class="lang zh-cn">
<p>You requested a page in Simplified Chinese (简体中文), would you like to proceed with this language setting?</p>
</div>
<div class="lang zh-tw">
<p>You requested a page in Traditional Chinese (繁體中文), would you like to proceed with this language setting?</p>
</div>
<a href="#" class="button yes" onclick="return false;">
<span class="lang en">Yes</span>
<span class="lang es">Sí</span>
<span class="lang ja">Yes</span>
<span class="lang ko">Yes</span>
<span class="lang ru">Yes</span>
<span class="lang zh-cn">是的</span>
<span class="lang zh-tw">没有</span>
</a>
<a href="#" class="button" onclick="$('#langMessage').hide();return false;">
<span class="lang en">No</span>
<span class="lang es">No</span>
<span class="lang ja">No</span>
<span class="lang ko">No</span>
<span class="lang ru">No</span>
<span class="lang zh-cn">没有</span>
<span class="lang zh-tw">没有</span>
</a>
</div>
</div> -->
<!-- Header -->
<div id="header-wrapper">
<div id="header">
<div class="wrap" id="header-wrap">
<div class="col-3 logo">
<a href="/index.html">
<img src="/assets/images/dac_logo.png"
srcset="/assets/images/dac_logo@2x.png 2x"
width="123" height="25" alt="Android Developers" />
</a>
<div class="btn-quicknav" id="btn-quicknav">
<a href="#" class="arrow-inactive">Quicknav</a>
<a href="#" class="arrow-active">Quicknav</a>
</div>
</div>
</div><!-- end header-wrap.wrap -->
</div><!-- end header -->
<!-- Secondary x-nav -->
<div id="nav-x">
<div class="wrap" style="position:relative;z-index:1">
<ul class="nav-x col-9 develop" style="width:100%">
<li class="guide"><a href="/ndk/guides/index.html">
Guides</a></li>
<li class="reference"><a href="/ndk/reference/index.html">
Reference</a></li>
<li class="samples"><a href="/ndk/samples/index.html">
Samples</a></li>
<li class="downloads"><a href="/ndk/downloads/index.html">
Downloads</a></li>
</li>
</ul>
</div>
</div>
<div id="searchResults" class="wrap" style="display:none;">
<h2 id="searchTitle">Results</h2>
<div id="leftSearchControl" class="search-control">Loading...</div>
</div>
</div> <!--end header-wrapper -->
<div id="sticky-header">
<div>
<a class="logo" href="#top"></a>
<a class="top" href="#top"></a>
<ul class="breadcrumb">
<li class="current">Setup</li>
</ul>
</div>
</div>
<div class="wrap clearfix" id="body-content">
<div class="col-3" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement">
<div id="devdoc-nav" class="scroll-pane">
<ul id="nav">
<li><strong>NDK</strong>
<ul>
<li><a href="/ndk/guides/index.html"><span class="en">Getting Started</span></a>
<ul>
<li><a href="setup.html">Setup</a></li>
<li><a href="concepts.html">Concepts</a></li>
</ul></li>
<li><a href="/ndk/guides/build.html"><span class="en">Building</span></a>
<ul>
<li><a href="">ndk-build</a></li>
<li><a href="">Android.mk</a></li>
<li><a href="">Application.mk</a></li>
<li><a href="">Standalone Toolchain</a></li>
</ul></li>
<li><a href="/ndk/guides/debug.html"><span class="en">Debugging</span></a>
<ul>
<li><a href="">ndk-gdb</a></li>
<li><a href="">ndk-stack</a></li>
</ul></li>
<li><a href="/ndk/guides/arch.html"><span class="en">Architectures and CPUs</span></a>
<ul>
<li><a href="">ABI Management</a></li>
<li><a href="">Neon</a></li>
<li><a href="">Mips</a></li>
<li><a href="">x86</a></li>
<li><a href="">x86-64</a></li>
<li><a href="">CPU Features</a></li>
</ul></li>
<li><a href="/ndk/guides/libs.html"><span class="en">Libraries</span></a>
<ul>
<li><a href="">Stable APIs</a></li>
<li><a href="">C++ Support</a></li>
<li><a href="">Prebuilt Libraries</a></li>
</ul></li>
<li><a href="/ndk/guides/sample.html"><span class="en">Sample Walkthrough</span></a>
<ul>
<li><a href="">hello-jni</a></li>
<li><a href="">native-activity</a></li>
<li><a href="">Teapot</a></li>
</ul></li>
<li><a href="/ndk/guides/atomics.html"><span class="en">Atomics</span></a></li>
<li><a href="/ndk/guides/importing.html"><span class="en">Importing Modules</span></a></li>
<li><a href="/ndk/guides/depends.html"><span class="en">ndk-depends</span></a></li>
<li><a href="/ndk/guides/system.html"><span class="en">System Image Issues</span></a></li>
<li><a href="/ndk/guides/licenses.html"><span class="en">Licenses</span></a></li>
</ul></li>
<li><strong>Radiance</strong>
<ul>
<li><a href="/ndk/guides/null.html"><span class="en">Stub 1</span></a>
<ul>
<li><a href="">Stublet</a></li>
<li><a href="">Stublet</a></li>
</ul></li>
<li><a href="/ndk/guides/null.html"><span class="en">Stub 2, etc.</span></a>
<ul>
<li><a href="">Another Stublet</a></li>
<li><a href="">Another Stublet</a></li>
</ul></li>
</ul></li>
</ul>
<script type="text/javascript">
<!--
buildToggleLists();
changeNavLang(getLangPref());
//-->
</script>
</div>
</div> <!-- end side-nav -->
<script>
$(document).ready(function() {
scrollIntoView("devdoc-nav");
});
</script>
<div class="col-12" id="doc-col" >
<h1 itemprop="name" >Setup</h1>
<div id="jd-content">
<div class="jd-descr" itemprop="articleBody">
<div id="qv-wrapper">
<div id="qv">
<h2>On this page</h2>
<ol>
<li><a href="#install">Installation</a></li>
<li><a href="#configure">Configuring Eclipse</a></li>
<li><a href="#verify">Verification</a></li>
</ol>
</li>
</ol>
</div>
</div>
<div class="contents">
<div class="textblock"><p>This document explains how to:</p>
<ul>
<li><a href="#install">Get</a> and install the NDK.</li>
<li><a href="#configure">Configure</a> your system and the Eclipse and the Android Development Tool
(ADT) for use with it.</li>
<li><a href="#verify">Verify</a>, using a simple sample, that everything is working as expected.
</li>
</ul>
<p>This document assumes that you are already familiar with Java-based Android development. For more
information on that topic, see the
<a href="/">Android developer site</a>.</p>
<h2 id="install">Installation</h2>
<p>To install and configure the NDK, follow these steps:</p>
<ol type="1">
<li>Get and install the <a href="/sdk/index.html">Android SDK</a>.if you
have not already done so.</li>
<li><a href="/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>Update your <code>PATH</code> environment variable with the location of the directory that
contains the NDK.</li>
</ol>
<h2 id="configure">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>Window</b> &gt; <b>Preferences</b>.</li>
<li>In the pane on the left side of the <i>Preferences</i> window, select <i>Android</i>.
The <i>Android</i> section expands, revealing a number of subsections.</li>
<li>Select <b>NDK</b>. In the pane on the right side of the <i>Preferences</i> window, browse to
the directory that contains the NDK.</li>
<li>Click <b>OK</b> to return to the <i>Package Explorer</i> display.</li>
</ol>
<h2 id="verify">Verification</h2>
<h3>Eclipse</h3>
<p>To confirm that you have installed the NDK, set it up correctly, and properly configured Eclipse,
follow these steps:</p>
<ol type="1">
<li>Import the hello-jni sample from <code>&lt;ndk&gt;/samples/</code>, as you would any other Android
project.</li>
<li>In the <i>Project Explorer</i> pane, right-click the project name (<i>HelloJni</i>). A
context menu appears.</li>
<li>From the context menu, select <b>Android Tools</b> &gt; <b>Add Native Support</b>. The
<i>Add Android Native Support</i> window appears.</li>
<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>
<p>Follow these steps to build from the command line:</p>
<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. do this by
typing <code>ndk-build</code> at the command prompt.</li>
<li>Build and install your project as you would a regular Android app written in Java. For more
information, see
<a href="/tools/building/index.html">Building and Running</a> and
<a href="/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 1.</p>
<img src="./images/verification_screen.png" srcset="./images/verification_screen@2x.png 2x" alt="Output: Hello from JNI!" id="figure2" />
<p class="img-caption">
<strong>Figure 1.</strong> Target-device screen after successful launch.
</p>
</div>
<div class="content-footer layout-content-row"
itemscope itemtype="http://schema.org/SiteNavigationElement">
<div class="paging-links layout-content-col col-10">
</div>
<div class="layout-content-col plus-container col-2" >
<div class="g-plusone" data-size="medium"></div>
</div>
</div>
</div> <!-- end jd-content -->
<div id="footer" class="wrap" >
<div id="copyright">
Except as noted, this content is
licensed under <a href="http://creativecommons.org/licenses/by/2.5/">
Creative Commons Attribution 2.5</a>. For details and
restrictions, see the <a href="/license.html">Content
License</a>.
</div>
<div id="footerlinks">
<p>
<a href="/about/index.html">About Android</a>&nbsp;&nbsp;|&nbsp;
<a href="/legal.html">Legal</a>&nbsp;&nbsp;|&nbsp;
<a href="/support.html">Support</a>
</p>
</div>
</div> <!-- end footer -->
</div><!-- end doc-content -->
</div> <!-- end body-content -->
<script src="https://developer.android.com/ytblogger_lists_unified.js" type="text/javascript"></script>
<script src="/jd_lists_unified.js?v=8" type="text/javascript"></script>
<script src="/jd_extras.js?v=10" type="text/javascript"></script>
<script src="/jd_collections.js?v=10" type="text/javascript"></script>
<script src="/jd_tag_helpers.js?v=5" type="text/javascript"></script>
</body>
</html>