What is the Android NDK? How can one use it? Why should one use it?

Technology CommunityCategory: AndroidWhat is the Android NDK? How can one use it? Why should one use it?
VietMX Staff asked 3 years ago

The NDK (Native Development Kit) is a tool that allows you to program in C/C++ for Android devices. It’s intended to integrate with the SDK (it’s described as a “companion tool”) and used only for performance-critical portions of a project. Many multimedia applications and video games use native code for processor-intensive tasks.

The performance improvements can come from three sources:

  • Firstly, the native code is compiled to a binary code and run directly on OS, while Java code is translated into Java byte-code and interpreted by Dalvik Virtual Machine (VM). At Android 2.2 or higher, a Just-In-Time (JIT) compiler is added to Dalvik VM to analyze and optimize the Java byte-code while the program is running (for example, JIT can compile a part of the byte-code to binary code before its execution). But in many cases, native code still runs faster than Java code.
  • The second source for performance improvements at NDK is that native code allows developers to make use of some processor features that are not accessible at Android SDK, such as NEON, a Single Instruction Multiple Data (SIMD) technology, allowing multiple data elements to be processed in parallel.
  • The third aspect is that we can optimize the critical code at an assembly level, which is a common practice in desktop software development.