1 ndk=true 2 3 ndk.win_download=android-ndk-r4-windows.zip 4 ndk.win_bytes=45778965 5 ndk.win_checksum=1eded98a7f5cd5e71f8ac74565f73f11 6 7 ndk.mac_download=android-ndk-r4-darwin-x86.zip 8 ndk.mac_bytes=50572163 9 ndk.mac_checksum=b7d5f149fecf951c05a79b045f00419f 10 11 ndk.linux_download=android-ndk-r4-linux-x86.zip 12 ndk.linux_bytes=49450682 13 ndk.linux_checksum=0892b0637d45d145e045cc68e163dee3 14 15 page.title=Android NDK 16 @jd:body 17 18 <h2 id="notes">Revisions</h2> 19 20 <p>The sections below provide information and notes about successive releases of 21 the NDK, as denoted by revision number. </p> 22 23 <script type="text/javascript"> 24 function toggleDiv(link) { 25 var toggleable = $(link).parent(); 26 if (toggleable.hasClass("closed")) { 27 //$(".toggleme", toggleable).slideDown("fast"); 28 toggleable.removeClass("closed"); 29 toggleable.addClass("open"); 30 $(".toggle-img", toggleable).attr("title", "hide").attr("src", "{@docRoot}assets/images/triangle-opened.png"); 31 } else { 32 //$(".toggleme", toggleable).slideUp("fast"); 33 toggleable.removeClass("open"); 34 toggleable.addClass("closed"); 35 $(".toggle-img", toggleable).attr("title", "show").attr("src", "/assets/images/triangle-closed.png"); 36 } 37 return false; 38 } 39 </script> 40 <style> 41 .toggleable { 42 padding: .25em 1em; 43 } 44 .toggleme { 45 padding: 1em 1em 0 2em; 46 line-height:1em; 47 } 48 .toggleable a { 49 text-decoration:none; 50 } 51 .toggleme a { 52 text-decoration:underline; 53 } 54 .toggleable.closed .toggleme { 55 display:none; 56 } 57 #jd-content .toggle-img { 58 margin:0; 59 } 60 </style> 61 62 <div class="toggleable open"> 63 <a href="#" onclick="return toggleDiv(this)"> 64 <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-img" height="9px" width="9px" /> 65 Android NDK, Revision 4</a> <em>(May 2010)</em> 66 <div class="toggleme"> 67 68 <dl> 69 <dt>General notes:</dt> 70 71 <dd> 72 <ul> 73 <li>Provides a simplified build system through the new <code>ndk-build</code> build 74 command. </li> 75 <li>Adds support for easy native debugging of generated machine code on production 76 devices through the new <code>ndk-gdb</code> command.</li> 77 <li>Adds a new Android-specific ABI for ARM-based CPU architectures, 78 <code>armeabi-v7a</code>. The new ABI extends the existing <code>armeabi</code> 79 ABI to include these CPU instruction set extensions: 80 <ul> 81 <li>Thumb-2 instructions</li> 82 <li>VFP hardware FPU instructions (VFPv3-D16)</li> 83 <li>Optional support for ARM Advanced SIMD (NEON) GCC intrinsics and VFPv3-D32. 84 Supported by devices such as Verizon Droid by Motorola, Google Nexus One, and 85 others.</li> 86 </ul> 87 <li>Adds a new <code>cpufeatures</code> static library (with sources) that lets 88 your app detect the host device's CPU features at runtime. Specifically, 89 applications can check for ARMv7-A support, as well as VFPv3-D32 and NEON 90 support, then provide separate code paths as needed.</li> 91 <li>Adds a sample application, <code>hello-neon</code>, that illustrates how to 92 use the <code>cpufeatures</code> library to check CPU features and then provide 93 an optimized code path using NEON instrinsics, if 94 supported by the CPU.</li> 95 <li>Lets you generate machine code for either or both of the instruction sets 96 supported by the NDK. For example, you can build for both ARMv5 and ARMv7-A 97 architectures at the same time and have everything stored to your application's 98 final <code>.apk</code>.</li> 99 <li>To ensure that your applications are available to users only if their 100 devices are capable of running them, Android Market now filters applications 101 based on the instruction set information included in your application — no 102 action is needed on your part to enable the filtering. Additionally, the Android 103 system itself also checks your application at install time and allows the 104 installation to continue only if the application provides a library that is 105 compiled for the device's CPU architecture.</li> 106 <li>Adds support for Android 2.2, including a new stable API for accessing 107 the pixel buffers of {@link android.graphics.Bitmap} objects from native 108 code.</li> 109 </ul> 110 </dd> 111 </dl> 112 </div> 113 </div> 114 115 <div class="toggleable closed"> 116 <a href="#" onclick="return toggleDiv(this)"> 117 <img src="{@docRoot}assets/images/triangle-opened.png" class="toggle-img" height="9px" width="9px" /> 118 Android NDK, Revision 3</a> <em>(March 2010)</em> 119 <div class="toggleme"> 120 121 <dl> 122 <dt>General notes:</dt> 123 124 <dd> 125 <ul> 126 <li>Adds OpenGL ES 2.0 native library support.</li> 127 <li>Adds a sample application,<code>hello-gl2</code>, that illustrates the use of 128 OpenGL ES 2.0 vertex and fragment shaders.</li> 129 <li>The toolchain binaries have been refreshed for this release with GCC 4.4.0, which should generate slightly more compact and efficient machine code than the previous one (4.2.1). The NDK also still provides the 4.2.1 binaries, which you can optionally use to build your machine code.</li> 130 </ul> 131 </dd> 132 </dl> 133 </div> 134 </div> 135 136 <div class="toggleable closed"> 137 <a href="#" onclick="return toggleDiv(this)"> 138 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-img" height="9px" width="9px" /> 139 Android NDK, Revision 2</a> <em>(September 2009)</em> 140 <div class="toggleme"> 141 142 <p>Originally released as "Android 1.6 NDK, Release 1".</p> 143 <dl> 144 <dt>General notes:</dt> 145 <dd> 146 <ul> 147 <li>Adds OpenGL ES 1.1 native library support.</li> 148 <li>Adds a sample application, <code>san-angeles</code>, that renders 3D 149 graphics through the native OpenGL ES APIs, while managing activity 150 lifecycle with a {@link android.opengl.GLSurfaceView} object. 151 </li> 152 </ul> 153 </dd> 154 </dl> 155 </div> 156 </div> 157 158 <div class="toggleable closed"> 159 <a href="#" onclick="return toggleDiv(this)"> 160 <img src="{@docRoot}assets/images/triangle-closed.png" class="toggle-img" height="9px" width="9px" /> 161 Android NDK, Revision 1</a> <em>(June 2009)</em> 162 <div class="toggleme"> 163 164 <p>Originally released as "Android 1.5 NDK, Release 1".</p> 165 <dl> 166 <dt>General notes:</dt> 167 <dd> 168 <ul> 169 <li>Includes compiler support (GCC) for ARMv5TE instructions, including Thumb-1 170 instructions. </li> 171 <li>Includes system headers for stable native APIs, documentation, and sample 172 applications.</li> 173 </ul> 174 </dd> 175 176 </dl> 177 </div> 178 </div> 179 180 181 <h2 id="overview">What is the Android NDK?</h2> 182 183 <p>The Android NDK is a toolset that lets you embed components that make use 184 of native code in your Android applications. 185 </p> 186 187 <p>Android applications run in the Dalvik virtual machine. The NDK allows 188 you to implement parts of your applications using native-code languages 189 such as C and C++. This can provide benefits to certain classes of applications, 190 in the form of reuse of existing code and in some cases increased speed.</p> 191 192 <p>The NDK provides:</p> 193 194 <ul> 195 <li>A set of tools and build files used to generate native code libraries from C 196 and C++ sources</li> 197 <li>A way to embed the corresponding native libraries into an application package 198 file (<code>.apk</code>) that can be deployed on Android devices</li> 199 <li>A set of native system headers and libraries that will be supported in all 200 future versions of the Android platform, starting from Android 1.5 </li> 201 <li>Documentation, samples, and tutorials</li> 202 </ul> 203 204 <p>The latest release of the NDK supports these ARM instruction sets:</p> 205 <ul> 206 <li>ARMv5TE (including Thumb-1 instructions)</li> 207 <li>ARMv7-A (including Thumb-2 and VFPv3-D16 instructions, with 208 optional support for NEON/VFPv3-D32 instructions)</li> 209 </ul> 210 211 <p>Future releases of the NDK will also support:</p> 212 213 <ul> 214 <li>x86 instructions (see CPU-ARCH-ABIS.TXT for more information)</li> 215 </ul> 216 217 <p>ARMv5TE machine code will run on all ARM-based Android devices. ARMv7-A will 218 run only on devices such as the Verizon Droid or Google Nexus One that have a 219 compatible CPU. The main difference between the two instruction sets is that 220 ARMv7-A supports hardware FPU, Thumb-2, and NEON instructions. You can target 221 either or both of the instruction sets — ARMv5TE is the default, but 222 switching to ARMv7-A is as easy as adding a single line to the application's 223 Application.mk file, without needing to change anything else in the file. You 224 can also build for both architectures at the same time and have everything 225 stored in the final <code>.apk</code>. For complete information is provided in the 226 CPU-ARCH-ABIS.TXT in the NDK package. </p> 227 228 <p>The NDK provides stable headers for libc (the C library), libm (the Math 229 library), OpenGL ES (3D graphics library), the JNI interface, and other 230 libraries, as listed in the section below.</p> 231 232 <p>The NDK will not benefit most applications. As a developer, you will need 233 to balance its benefits against its drawbacks; notably, using native code does 234 not result in an automatic performance increase, but does always increase 235 application complexity. Typical good candidates for the NDK are self-contained, 236 CPU-intensive operations that don't allocate much memory, such as signal processing, 237 physics simulation, and so on. Simply re-coding a method to run in C usually does 238 not result in a large performance increase. The NDK can, however, can be 239 an effective way to reuse a large corpus of existing C/C++ code.</p> 240 241 <p>Please note that the NDK <em>does not</em> enable you to develop native-only 242 applications. Android's primary runtime remains the Dalvik virtual machine.</p> 243 244 <h2 id="contents">Contents of the NDK</h2> 245 246 <h4>Development tools</h4> 247 248 <p>The NDK includes a set of cross-toolchains (compilers, linkers, etc..) that 249 can generate native ARM binaries on Linux, OS X, and Windows (with Cygwin) 250 platforms.</p> 251 252 <p>It provides a set of system headers for stable native APIs that are 253 guaranteed to be supported in all later releases of the platform:</p> 254 255 <ul> 256 <li>libc (C library) headers</li> 257 <li>libm (math library) headers</li> 258 <li>JNI interface headers</li> 259 <li>libz (Zlib compression) headers</li> 260 <li>liblog (Android logging) header</li> 261 <li>OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers</li> 262 <li>libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).</li> 263 <li>A Minimal set of headers for C++ support</li> 264 </ul> 265 266 <p>The NDK also provides a build system that lets you work efficiently with your 267 sources, without having to handle the toolchain/platform/CPU/ABI details. You 268 create very short build files to describe which sources to compile and which 269 Android application will use them — the build system compiles the sources 270 and places the shared libraries directly in your application project. </p> 271 272 <p class="caution"><strong>Important:</strong> With the exception of the 273 libraries listed above, native system libraries in the Android platform are 274 <em>not</em> stable and may change in future platform versions. 275 Your applications should <em>only</em> make use of the stable native system 276 libraries provided in this NDK. </p> 277 278 <h4>Documentation</h4> 279 280 <p>The NDK package includes a set of documentation that describes the 281 capabilities of the NDK and how to use it to create shared libraries for your 282 Android applications. In this release, the documentation is provided only in the 283 downloadable NDK package. You can find the documentation in the 284 <code><ndk>/docs/</code> directory. Included are these files:</p> 285 286 <ul> 287 <li>INSTALL.TXT — describes how to install the NDK and configure it for 288 your host system</li> 289 <li>OVERVIEW.TXT — provides an overview of the NDK capabilities and 290 usage</li> 291 <li>ANDROID-MK.TXT — describes the use of the Android.mk file, which 292 defines the native sources you want to compile</li> 293 <li>APPLICATION-MK.TXT — describes the use of the Application.mk file, 294 which describes the native sources required by your Android application</li> 295 <li>HOWTO.TXT — information about common tasks associated with NDK 296 development.</li> 297 <li>SYSTEM-ISSUES.TXT — known issues in the Android system images 298 that you should be aware of, if you are developing using the NDK. </li> 299 <li>STABLE-APIS.TXT — a complete list of the stable APIs exposed 300 by headers in the NDK.</li> 301 <li>CPU-ARCH-ABIS.TXT — a description of supported CPU architectures 302 and how to target them. </li> 303 <li>CPU-FEATURES.TXT — a description of the <code>cpufeatures</code> 304 static library that lets your application code detect the target device's 305 CPU family and the optional features at runtime. </li> 306 <li>CPU-ARM-NEON.TXT — a description of how to build with optional 307 ARM NEON / VFPv3-D32 instructions. </li> 308 <li>CHANGES.TXT — a complete list of changes to the NDK across all 309 releases.</li> 310 </ul> 311 312 <p>Additionally, the package includes detailed information about the "bionic" 313 C library provided with the Android platform that you should be aware of, if you 314 are developing using the NDK. You can find the documentation in the 315 <code><ndk>/docs/system/libc/</code> directory:</p> 316 317 <ul> 318 <li>OVERVIEW.TXT — provides an overview of the "bionic" C library and the 319 features it offers.</li> 320 </ul> 321 322 <h4>Sample applications</h4> 323 324 <p>The NDK includes sample Android applications that illustrate how to use 325 native code in your Android applications. For more information, see 326 <a href="#samples">Using the Sample Applications</a>.</p> 327 328 <h2 id="requirements">System and Software Requirements</h2> 329 330 <p>The sections below describe the system and software requirements for using 331 the Android NDK, as well as platform compatibility considerations that affect 332 appplications using libraries produced with the NDK. </p> 333 334 <h4>The Android SDK</h4> 335 <ul> 336 <li>A complete Android SDK installation (including all dependencies) is 337 required.</li> 338 <li>Android 1.5 SDK or later version is required.</li> 339 </ul> 340 341 <h4>Supported operating systems</h4> 342 <ul> 343 <li>Windows XP (32-bit) or Vista (32- or 64-bit)</li> 344 <li>Mac OS X 10.4.8 or later (x86 only)</li> 345 <li>Linux (32- or 64-bit, tested on Linux Ubuntu Dapper Drake)</li> 346 </ul> 347 348 <h4>Required development tools</h4> 349 <ul> 350 <li>For all development platforms, GNU Make 3.81 or later is required. Earlier 351 versions of GNU Make might work but have not been tested.</li> 352 <li>A recent version of awk (either GNU Awk or Nawk) is also required.</li> 353 <li>For Windows, <a 354 href="http://www.cygwin.com">Cygwin</a> 1.7 or higher is required. The NDK 355 will <em>not</em> work with Cygwin 1.5 installations.</li> 356 </ul> 357 358 <h4>Android platform compatibility</h4> 359 <ul> 360 <li>The native libraries created by the Android NDK can only be used on 361 devices running the Android 1.5 platform version or later. This is due to 362 toolchain and ABI related changes that make the native libraries incompatible 363 with 1.0 and 1.1 system images.</li> 364 <li>For this reason, you should use native libraries produced with the NDK in 365 applications that are deployable to devices running the Android 1.5 platform 366 version or later. </li> 367 <li>To ensure compatibility, an application using a native library 368 produced with the NDK <em>must</em> declare a <a 369 href="{@docRoot}guide/topics/manifest/uses-sdk-element.html"><code><uses-sdk></code></a> 370 element in its manifest file, with an <code>android:minSdkVersion</code> attribute 371 value of "3" or higher. For example: 372 373 <pre style="margin:1em;"><manifest> 374 ... 375 <uses-sdk android:minSdkVersion="3" /> 376 ... 377 </manifest></pre> 378 </li> 379 380 <li>If you use this NDK to create a native library that uses the 381 OpenGL ES APIs, the application containing the library can be deployed only to 382 devices running the minimum platform versions described in the table below. 383 To ensure compatibility, make sure that your application declares the proper 384 <code>android:minSdkVersion</code></a> attribute value, as given in the table.</p> 385 386 <table style="margin:1em;"> 387 <tr> 388 <th>OpenGL ES Version Used</th> 389 <th>Compatible Android Platform(s)</th> 390 <th>Required uses-sdk Attribute</th> 391 </tr> 392 <tr><td>OpenGL ES 1.1</td><td>Android 1.6 and higher</td><td><code>android:minSdkVersion="4"</code></td></tr> 393 <tr><td>OpenGL ES 2.0</td><td>Android 2.0 and higher</td><td><code>android:minSdkVersion="5"</code></td></tr> 394 </table> 395 396 <p>For more information about API Level and its relationship to Android 397 platform versions, see <a href="{@docRoot}guide/appendix/api-levels.html"> 398 Android API Levels</a>.</p></li> 399 400 <li>Additionally, an application using the OpenGL ES APIs should declare a 401 <code><uses-feature></code> element in its manifest, with an 402 <code>android:glEsVersion</code> attribute that specifies the minimum OpenGl ES 403 version required by the application. This ensures that Android Market will show 404 your application only to users whose devices are capable of supporting your 405 application. For example: 406 407 <pre style="margin:1em;"><manifest> 408 ... 409 <!-- Declare that the application uses the OpenGL ES 2.0 API and is designed 410 to run only on devices that support OpenGL ES 2.0 or higher. --> 411 <uses-feature android:glEsVersion="0x00020000" /> 412 ... 413 </manifest></pre> 414 415 <p>For more information, see the <a 416 href="{@docRoot}guide/topics/manifest/uses-feature-element.html"><code><uses-feature></code></a> 417 documentation.</p></li> 418 419 <li>If you use this NDK to create a native library that uses the API to access 420 Android {@link android.graphics.Bitmap} pixel buffers, the application 421 containing the library can be deployed only to devices running Android 2.2 (API 422 level 8) or higher. To ensure compatibility, make sure that your application 423 declares <code><uses-sdk android:minSdkVersion="8" /></code>attribute 424 value in its manifest.</li> 425 </ul> 426 427 <h2 id="installing">Installing the NDK</h2> 428 429 <p>Installing the NDK on your development computer is straightforward and 430 involves extracting the NDK from its download package. Unlike previous releases, 431 there is no need to run a host-setup script.</p> 432 433 <p>Before you get started make sure that you have downloaded the latest <a 434 href="{@docRoot}sdk/index.html">Android SDK</a> and upgraded your applications 435 and environment as needed. The NDK will not work with older versions of the 436 Android SDK. Also, take a moment to review the <a href="#requirements">System 437 and Software Requirements</a> for the NDK, if you haven't already. </p> 438 439 <p>To install the NDK, follow these steps:</p> 440 441 <ol> 442 <li>From the table at the top of this page, select the NDK package that is 443 appropriate for your development computer and download the package.</li> 444 <li>Uncompress the NDK download package using tools available on your computer. 445 When uncompressed, the NDK files are contained in a directory called 446 <code>android-ndk-<version></code>. You can rename the NDK directory if 447 necessary and you can move it to any location on your computer. This 448 documentation refers to the NDK directory as <code><ndk></code>. </li> 449 </ol> 450 451 <p>You are now ready start working with the NDK. </p> 452 453 <h2 id="gettingstarted">Getting Started with the NDK</h2> 454 455 <p>Once you've installed the NDK successfully, take a few minutes to read the 456 documentation included in the NDK. You can find the documentation in the 457 <code><ndk>/docs/</code> directory. In particular, please read the 458 OVERVIEW.TXT document completely, so that you understand the intent of the NDK 459 and how to use it.</p> 460 461 <p>If you used a previous version of the NDK, take a moment to review the 462 list of NDK changes in the CHANGES.TXT document. </p> 463 464 <p>Here's the general outline of how you work with the NDK tools:</p> 465 466 <ol> 467 <li>Place your native sources under 468 <code><project>/jni/...</code></li> 469 <li>Create <code><project>/jni/Android.mk</code> to 470 describe your native sources to the NDK build system</li> 471 <li>Optional: Create <code><project>/jni/Application.mk</code>.</li> 472 <li>Build your native code by running the 'ndk-build' script from your projet's directory. 473 It is located in the top-level NDK directory: 474 475 <p><pre> 476 $ cd <project> 477 $ <ndk>/ndk-build 478 </pre></p> 479 480 <p>The build tools copy the stripped, shared libraries needed by your 481 application to the proper location in the application's project directory.</p> 482 </li> 483 484 <li>Finally, compile your application using the SDK tools in the usual way. The 485 SDK build tools will package the shared libraries in the application's 486 deployable <code>.apk</code> file. </p></li> 487 488 </ol> 489 490 <p>For complete information on all of the steps listed above, please see the 491 documentation included with the NDK package. </p> 492 493 494 <h2 id="samples">Using the Sample Applications</h2> 495 496 <p>The NDK includes sample applications that illustrate how to use native 497 code in your Android applications:</p> 498 499 <ul> 500 <li><code>hello-jni</code> — a simple application that loads a string from 501 a native method implemented in a shared library and then displays it in the 502 application UI. </li> 503 <li><code>two-libs</code> — a simple application that loads a shared 504 library dynamically and calls a native method provided by the library. In this 505 case, the method is implemented in a static library imported by the shared 506 library. </li> 507 <li><code>san-angeles</code> — a simple application that renders 3D 508 graphics through the native OpenGL ES APIs, while managing activity lifecycle 509 with a {@link android.opengl.GLSurfaceView} object. </li> 510 <li><code>hello-gl2</code> — a simple application that renders a triangle 511 using OpenGL ES 2.0 vertex and fragment shaders.</li> 512 <li><code>hello-neon</code> — a simple application that shows how to use 513 the <code>cpufeatures</code> library to check CPU capabilities at runtime, 514 then use NEON intrinsics if supported by the CPU. Specifically, the 515 application implements two versions of a tiny benchmark for a FIR filter 516 loop, a C version and a NEON-optimized version for devices that support it.</li> 517 <li><code>bitmap-plasma</code> — a simple application that demonstrates 518 how to access the pixel buffers of Android {@link android.graphics.Bitmap} 519 objects from native code, and uses this to generate an old-school "plasma" 520 effect. </li> 521 </ul> 522 523 <p>For each sample, the NDK includes the corresponding C source code and the 524 necessary Android.mk and Application.mk files. There are located under 525 <code><ndk>/samples/<name>/</code> and their source code can be found under 526 <code><ndk>/samples/<name>/jni/</code>. </p> 527 528 <p>You can build the shared libraries for the sample apps by going into <code><ndk>/samples/<name>/</code> 529 then calling the <code>ndk-build</code> command. The generated shared libraries will be located under 530 <code><ndk>/samples/<name>/libs/armeabi/</code> for (ARMv5TE machine code) and/or 531 <code><ndk>/samples/<name>/libs/armeabi-v7a/</code> for (ARMv7 machine code). 532 </p> 533 534 <p>Next, build the sample Android applications that use the shared 535 libraries:</p> 536 537 <ul> 538 <li>If you are developing in Eclipse with ADT, use the New Project Wizard to 539 create a new Android project for each sample, using the "Import from Existing 540 Source" option and importing the source from 541 <code><ndk>/apps/<app_name>/project/</code>. Then, set up an AVD, if 542 necessary, and build/run the application in the emulator. For more information 543 about creating a new Android project in Eclipse, see <a 544 href="{@docRoot}guide/developing/eclipse-adt.html">Developing in 545 Eclipse</a>.</li> 546 <li>If you are developing with Ant, use the <code>android</code> tool to create 547 the build file for each of the sample projects at 548 <code><ndk>/apps/<app_name>/project/</code>. Then set up an AVD, if 549 necessary, build your project in the usual way, and run it in the emulator. 550 For more information, see <a 551 href="{@docRoot}guide/developing/other-ide.html">Developing in Other 552 IDEs</a>.</li> 553 </ul> 554 555 <h2>Discussion Forum and Mailing List</h2> 556 557 <p>If you have questions about the NDK or would like to read or contribute to 558 discussions about it, please visit the <a 559 href="http://groups.google.com/group/android-ndk">android-ndk</a> group and 560 mailing list.</p> 561 562 563 564