Skip to main content

What are NDK native APIs?

The Android NDK provides a set of native APIs that allow you to write performance-critical portions of your Android apps in C and C++. These APIs include both standard C/C++ libraries and Android-specific functionality.

Available API categories

The NDK includes the following types of native APIs:

Standard C/C++ libraries

POSIX-compatible APIs provided by Bionic, Android’s C library

Android-specific APIs

Native activity, asset management, logging, and more

Graphics and media

OpenGL ES, Vulkan, Media NDK, Camera2 NDK

Neural Networks

NNAPI for hardware-accelerated machine learning

API levels and compatibility

NDK APIs are tied to Android API levels. Each API level corresponds to an Android platform release and determines which APIs are available.

Understanding API levels

minSdkVersion
integer
required
The minimum API level your app supports. Determines which APIs you can safely use.
targetSdkVersion
integer
required
The API level your app is designed for. Affects behavior changes and optimizations.
compileSdkVersion
integer
required
The API level used to compile your app. Should be the latest available version.

API availability by Android version

Android VersionAPI LevelNotable Native APIs
Android 1535Latest Vulkan extensions, Camera improvements
Android 1434Enhanced NNAPI, Media codecs
Android 1333Vulkan 1.3, Java interop improvements
Android 1231-32Game Activity, Performance Hint API
Android 1130Native File Descriptor API, ImageDecoder
Android 1029Neural Networks API 1.2, Vulkan 1.1
Android 928Neural Networks API, ImageDecoder
Android 8.127Shared memory API, Hardware buffers
Android 8.026AAudio, Choreographer, Vulkan 1.0

Stability guarantees

The NDK provides different stability guarantees for different types of APIs:

Stable APIs

Stable APIs
Guaranteed
These APIs are guaranteed to be available and maintain backward compatibility across Android versions. Safe to use in production apps.
Stable APIs include:
  • Standard C library (libc)
  • Math library (libm)
  • C++ standard library (libc++)
  • OpenGL ES
  • Android-specific libraries (libandroid, liblog, etc.)

Preview and experimental APIs

Preview and experimental APIs may change or be removed in future releases. Use them cautiously and be prepared to update your code.
Experimental APIs are useful for:
  • Testing new features before they become stable
  • Providing feedback to the Android team
  • Prototyping and proof-of-concept work
Do not rely on experimental APIs in production apps without a fallback plan.

Finding API documentation

Official NDK API documentation is available at:

NDK API Reference

Complete reference for all Android-specific native APIs

Code example: Checking API level at runtime

#include <android/api-level.h>
#include <android/log.h>

#define LOG_TAG "NDK_Example"

void check_api_level() {
    int api_level = android_get_device_api_level();
    
    if (api_level >= 29) {
        __android_log_print(ANDROID_LOG_INFO, LOG_TAG, 
            "Running on Android 10 or higher (API %d)", api_level);
        // Use Android 10+ specific APIs
    } else if (api_level >= 26) {
        __android_log_print(ANDROID_LOG_INFO, LOG_TAG, 
            "Running on Android 8.0+ (API %d)", api_level);
        // Use Android 8.0+ specific APIs
    } else {
        __android_log_print(ANDROID_LOG_WARN, LOG_TAG, 
            "Running on older Android (API %d)", api_level);
        // Fallback implementation
    }
}

Code example: Conditional compilation

#include <android/api-level.h>

// Use compile-time API level checking
#if __ANDROID_API__ >= 29
    // Code for Android 10+
    #include <android/imagedecoder.h>
    
    void use_image_decoder() {
        // Use ImageDecoder APIs
    }
#else
    // Fallback for older versions
    void use_image_decoder() {
        // Use alternative image loading
    }
#endif

Best practices

Use android_get_device_api_level() at runtime or __ANDROID_API__ at compile time to ensure APIs are available before calling them.
Newer API levels provide better performance, security, and features. Update your targetSdkVersion regularly.
If you need to support older devices, implement alternative code paths for missing APIs.
Many NDK libraries provide their own feature detection mechanisms. Use them instead of manual API level checks when available.

Next steps

Android-specific APIs

Learn about NativeActivity, Asset Manager, logging, and other Android-specific APIs

Bionic status

Check POSIX compliance and available functions by API level

Platform APIs

Understand platform API availability and compatibility

NDK Guides

Official NDK development guides

Build docs developers (and LLMs) love