# android/ndk-samples

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/android-ndk-samples).**

10,475 stars · 4,259 forks · C++ · apache-2.0

## Links

- GitHub: https://github.com/android/ndk-samples
- Homepage: http://developer.android.com/ndk
- awesome-repositories: https://awesome-repositories.com/repository/android-ndk-samples.md

## Description

The Android NDK samples provide a comprehensive collection of code examples demonstrating how to integrate C and C++ native code into Android applications. This repository serves as a practical guide for developers utilizing the Android Native Development Kit to implement performance-critical application components that require direct hardware access and low-level system interaction.

The project highlights the use of the Java Native Interface to bridge managed code with native modules, enabling cross-language function calls and efficient data exchange. It demonstrates how to manage native activity lifecycles, configure build toolchains for multi-architecture compilation, and package native libraries to ensure compatibility across diverse mobile processor instruction sets.

These samples cover a broad capability surface, including high-performance graphics rendering with Vulkan and OpenGL ES, low-latency audio processing, and on-device machine learning inference. The collection also illustrates advanced techniques for memory management, native code debugging, and performance optimization, such as hardware-assisted memory sanitization and CPU-specific instruction set targeting.

## Tags

### Programming Languages & Runtimes

- [Software Development Kits](https://awesome-repositories.com/f/programming-languages-runtimes/language-ecosystems-tooling/software-development-kits.md) — Provides a toolset for implementing performance-critical application components in C and C++ with direct hardware access.
- [Native C Interoperability](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/native-c-interoperability.md) — Bridges managed Java or Kotlin code with native C and C++ modules for cross-language function calls and data exchange.
- [C Function Bindings](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/native-c-interoperability/c-function-bindings.md) — Maps native functions to C and C++ implementations explicitly to improve performance and maintainability. ([source](https://cdn.jsdelivr.net/gh/android/ndk-samples@main/README.md))
- [C++ Runtimes](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/native-c-interoperability/c-runtimes.md) — Links applications against standard C++ library implementations to provide essential language features within native code. ([source](https://developer.android.com/ndk/guides/libs))
- [Multi-Target Compilers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/multi-target-compilers.md) — Compiles native code for multiple instruction sets to ensure compatibility across diverse hardware platforms. ([source](https://developer.android.com/ndk/guides/abis))
- [Native Library Integrations](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/foreign-function-interfaces/native-library-integrations.md) — Imports existing static or shared binary libraries to accelerate build times and distribute compiled code. ([source](https://developer.android.com/ndk/guides/prebuilts))
- [Native Memory Lifecycle Management](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/native-c-interoperability/native-memory-lifecycle-management.md) — Controls the lifecycle of native references to managed objects to prevent memory leaks. ([source](https://developer.android.com/ndk/guides/jni-tips))

### Graphics & Multimedia

- [Low-Latency Implementation](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/low-latency-implementation.md) — Provides high-performance C and C++ APIs for real-time audio synthesis, recording, and playback with minimal hardware delay. ([source](https://developer.android.com/ndk/guides/audio/opensl))
- [Audio Processing](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing.md) — Implements low-latency audio input and output streams by interfacing with native system-level audio hardware drivers. ([source](https://developer.android.com/ndk/guides/libs))
- [Native API Integration](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/native-api-integration.md) — Provides access to native audio APIs through C and C++ headers for high-performance sound applications. ([source](https://developer.android.com/ndk/guides/audio/opensl/getting-started))
- [Hardware-Accelerated Rendering](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/rendering/engines/graphics-pipeline-architectures/hardware-accelerated-rendering.md) — Implements high-performance 2D and 3D visuals using low-level graphics APIs.
- [Graphics Rendering APIs](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/rendering/graphics-apis-bindings/graphics-rendering-apis.md) — Utilizes low-overhead, cross-platform APIs to generate real-time 3D visuals while minimizing CPU usage. ([source](https://developer.android.com/ndk/guides/graphics))
- [3D Graphics Pipelines](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/rendering/systems/3d-graphics-pipelines.md) — Provides low-level interfaces for hardware-accelerated 3D graphics rendering. ([source](https://developer.android.com/ndk/guides/stable_apis))
- [Performance Optimization](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/performance-optimization.md) — Enables optimization of audio paths to balance latency, power consumption, and hardware effect availability. ([source](https://developer.android.com/ndk/guides/audio/opensl/opensl-prog-notes))
- [Audio Streaming Engines](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-streaming-engines.md) — Offers low-latency audio playback and recording interfaces for high-performance sound applications. ([source](https://developer.android.com/ndk/guides/stable_apis))
- [Native Activity Bridges](https://awesome-repositories.com/f/graphics-multimedia/native-activity-bridges.md) — Executes high-performance graphics rendering by bridging Android system lifecycle events directly to native code. ([source](https://developer.android.com/ndk/guides/graphics/getting-started))
- [Audio Playback](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-playback.md) — Provides configurable audio players for streaming content from URIs or buffer queues with playback control. ([source](https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android))
- [Engine Managers](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/engine-managers.md) — Initializes and coordinates thread-safe audio engines that support multiple concurrent objects. ([source](https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android))
- [Interactive Synthesis](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/interactive-synthesis.md) — Allows implementing real-time sound processing and playback logic for responsive musical instruments and games. ([source](https://developer.android.com/ndk/guides/audio))
- [Signal Generation](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/signal-generation.md) — Enables synthesis and playback of digital audio waveforms using low-latency native interfaces. ([source](https://developer.android.com/ndk/guides/audio))
- [Audio Recording](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-recording.md) — Captures audio from device hardware using specified data locators and formats for processing or storage. ([source](https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android))
- [Render Pass Consolidators](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/post-processing-pipelines/multi-pass-rendering-pipelines/render-pass-consolidators.md) — Consolidates rendering operations to reduce the overhead of starting and ending passes on mobile GPU architectures. ([source](https://developer.android.com/ndk/guides/graphics/design-notes))
- [Runtime Shader Compilers](https://awesome-repositories.com/f/graphics-multimedia/graphics-engines-rendering/shaders/shader-cross-compilation-pipelines/runtime-shader-compilers.md) — Provides C and C++ APIs to perform just-in-time compilation of shader source code into SPIR-V modules. ([source](https://developer.android.com/ndk/guides/graphics/shader-compilers))
- [Multimedia Processing](https://awesome-repositories.com/f/graphics-multimedia/media-processing-analysis/multimedia-processing.md) — Provides low-level interfaces for media extraction, codec operations, and multimedia output handling. ([source](https://developer.android.com/ndk/guides/stable_apis))
- [Asynchronous Callbacks](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/asynchronous-callbacks.md) — Processes audio events using non-blocking handlers that operate on internal system threads. ([source](https://developer.android.com/ndk/guides/audio/opensl/opensl-prog-notes))
- [Floating-Point Processing](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/floating-point-processing.md) — Allows representing audio data using floating-point numbers to increase dynamic range and headroom. ([source](https://developer.android.com/ndk/guides/audio/sampling-audio))
- [Latency Measurement](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-processing/latency-measurement.md) — Provides utilities for measuring round-trip audio latency to optimize performance-critical sound applications. ([source](https://developer.android.com/ndk/guides/audio/audio-latency))
- [Data Streamers](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-streaming-engines/data-streamers.md) — Supports transferring audio samples between applications and device hardware using configured streams. ([source](https://developer.android.com/ndk/guides/audio/aaudio/aaudio))
- [Stream Configuration](https://awesome-repositories.com/f/graphics-multimedia/audio-music/audio-streaming-engines/stream-configuration.md) — Allows definition of stream parameters like device, sharing mode, and format to balance hardware requirements. ([source](https://developer.android.com/ndk/guides/audio/aaudio/aaudio))
- [Context Managers](https://awesome-repositories.com/f/graphics-multimedia/context-managers.md) — Allocates and manages rendering surfaces and contexts to bridge native code with graphics hardware. ([source](https://developer.android.com/ndk/guides/stable_apis))
- [Descriptor Binding Groupers](https://awesome-repositories.com/f/graphics-multimedia/graphics-and-media/shape-drawing/draw-call-sorters/descriptor-binding-groupers.md) — Organizes descriptor sets by update frequency to minimize rebinding overhead and improve efficiency during draw calls. ([source](https://developer.android.com/ndk/guides/graphics/design-notes))
- [Native Image Decoders](https://awesome-repositories.com/f/graphics-multimedia/media-processing-analysis/media-manipulation/media-processing-workflows/image-processing-pipelines/image-format-decoders/native-image-decoders.md) — Converts encoded image files into raw pixel data directly within native code using various input sources. ([source](https://developer.android.com/ndk/guides/image-decoder))
- [Validation Layers](https://awesome-repositories.com/f/graphics-multimedia/validation-layers.md) — Utilizes system-provided validation layers to enable diagnostic features dynamically without modifying application binaries. ([source](https://developer.android.com/ndk/guides/graphics/validation-layer))

### Mobile Development

- [Android Development](https://awesome-repositories.com/f/mobile-development/android-ecosystem/android-development.md) — Provides tools and frameworks for building high-performance applications using C and C++ on Android.
- [Android Activity Lifecycle Management](https://awesome-repositories.com/f/mobile-development/android-activity-lifecycle-management.md) — Provides native interfaces for managing Android activity lifecycles and input events without managed code. ([source](https://developer.android.com/ndk/guides/concepts))
- [Camera Capture Controllers](https://awesome-repositories.com/f/mobile-development/mobile-capabilities/camera-integration/camera-capture-controllers.md) — Performs fine-grained photo capture and processing using low-level hardware interfaces. ([source](https://developer.android.com/ndk/guides/stable_apis))

### Software Engineering & Architecture

- [Native Bridges](https://awesome-repositories.com/f/software-engineering-architecture/native-bridges.md) — Connects managed runtime environments with native code via a standardized mechanism for cross-language function calls.
- [Instruction Set Targets](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/performance-optimization/computational-efficiency/cpu-optimization-strategies/hardware-instruction-targeting/instruction-set-targets.md) — Configures the build system to generate native binaries for specific CPU instruction sets. ([source](https://developer.android.com/ndk/guides/application_mk))
- [Binary Compatibility Strategies](https://awesome-repositories.com/f/software-engineering-architecture/binary-compatibility-strategies.md) — Manages minimum API levels and NDK versions to ensure native library compatibility. ([source](https://developer.android.com/ndk/guides/middleware-vendors))
- [Computational Optimizers](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/performance-optimization/computational-efficiency/computational-graph-optimizers/computational-optimizers.md) — Performs parallel data processing using advanced instruction sets to increase execution speed in low-level code. ([source](https://developer.android.com/ndk/guides/cpu-arm-neon))
- [API Call Interceptors](https://awesome-repositories.com/f/software-engineering-architecture/software-architecture/architectural-patterns/plugin-module-systems/dynamic-library-loaders/graphics-call-interceptors/api-call-interceptors.md) — Injects custom logic into graphics API calls to monitor and modify rendering behavior at runtime. ([source](https://developer.android.com/ndk/guides/rootless-debug-gles))
- [Exception Handling Strategies](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/exception-logic-structures/exception-handling-strategies.md) — Detects and clears exceptions thrown by managed code within native methods to ensure stable execution. ([source](https://developer.android.com/ndk/guides/jni-tips))
- [Library Compatibility Managers](https://awesome-repositories.com/f/software-engineering-architecture/library-compatibility-managers.md) — Aligns minimum API levels and build tool versions across native libraries to prevent incompatibilities. ([source](https://developer.android.com/ndk/guides/common-problems))
- [Code Optimization](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/code-optimization.md) — Uses runtime execution profiles to guide compiler decisions on code layout and inlining for faster execution. ([source](https://developer.android.com/ndk/guides/pgo))

### Artificial Intelligence & ML

- [On-Device Inference Engines](https://awesome-repositories.com/f/artificial-intelligence-ml/on-device-inference-engines.md) — Executes complex neural network models directly on mobile hardware for fast inference.
- [Hardware Acceleration](https://awesome-repositories.com/f/artificial-intelligence-ml/machine-learning/infrastructure/model-optimization-and-inference/hardware-and-acceleration/hardware-acceleration.md) — Runs on-device machine learning models using hardware-accelerated operations to improve processing speeds. ([source](https://developer.android.com/ndk/guides/stable_apis))
- [Model Inference](https://awesome-repositories.com/f/artificial-intelligence-ml/machine-learning/infrastructure/model-inference-serving/model-integration-pipelines/model-inference.md) — Supports applying compiled models to input data using synchronous or asynchronous processing for high-performance inference. ([source](https://developer.android.com/ndk/guides/neuralnetworks))
- [Machine Learning Optimization](https://awesome-repositories.com/f/artificial-intelligence-ml/machine-learning/infrastructure/model-optimization-and-inference/training-algorithms/machine-learning-optimization.md) — Configures and refines mathematical models for specific hardware processors to balance power consumption and processing speed. ([source](https://developer.android.com/ndk/guides/neuralnetworks))

### Operating Systems & Systems Programming

- [Low-Latency Concurrency Patterns](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/memory-allocation-libraries/low-level-system-operations/low-level-systems-programming/low-latency-concurrency-patterns.md) — Facilitates real-time sound synthesis, recording, and playback by interacting with low-level audio hardware.
- [Graphics Rendering Interfaces](https://awesome-repositories.com/f/operating-systems-systems-programming/platform-development-integration/native-applications/graphics-rendering-interfaces.md) — Enables hardware-accelerated rendering using Vulkan and OpenGL ES within native application modules.
- [Memory Safety Diagnostics](https://awesome-repositories.com/f/operating-systems-systems-programming/memory-safety-diagnostics.md) — Employs processor-level tagging and instrumentation to detect memory corruption and safety violations in native code.
- [Native Compatibility Layers](https://awesome-repositories.com/f/operating-systems-systems-programming/native-compatibility-layers.md) — Android NDK uses preprocessor macros and dynamic linking techniques to conditionally execute code based on the minimum supported OS version and available platform features. ([source](https://developer.android.com/ndk/guides/sdk-versions))
- [Hardware Acceleration](https://awesome-repositories.com/f/operating-systems-systems-programming/hardware-interfacing-drivers/hardware-acceleration.md) — Utilizes low-level system drivers and hardware-specific instruction sets to accelerate media and compute workloads.
- [Latency Minimizers](https://awesome-repositories.com/f/operating-systems-systems-programming/input-and-audio-management/latency-minimizers.md) — Configures recording parameters and hardware usage to reduce the delay between capturing and processing audio. ([source](https://developer.android.com/ndk/guides/audio/audio-latency))
- [Native Binary Runtimes](https://awesome-repositories.com/f/operating-systems-systems-programming/instruction-translation-accelerators/dynamic-binary-translators/native-binary-runtimes.md) — Packages and extracts architecture-optimized binary modules at runtime to ensure cross-platform compatibility.
- [Hardware Tagging](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/dynamic-memory-allocation/custom-memory-allocators/hardware-tagging.md) — Applies hardware memory tags to custom allocators by aligning memory to 16-byte granules and using specific processor instructions. ([source](https://developer.android.com/ndk/guides/arm-mte))
- [Memory Allocation Tracers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/allocation-strategies/dynamic-memory-allocation/memory-allocation-tracers.md) — Monitors heap usage and intercepts memory allocation calls to diagnose leaks and management issues in native code. ([source](https://developer.android.com/ndk/guides/debug))
- [Audio Buffers](https://awesome-repositories.com/f/operating-systems-systems-programming/kernel-core-internals/process-and-memory-management/memory-management/buffer-and-cache-management/binary-buffer-managers/trace-buffer-managers/audio-buffers.md) — Handles PCM audio data streams for playback and recording using high-performance buffer queues. ([source](https://developer.android.com/ndk/guides/audio/opensl/android-extensions))
- [Acceleration Detectors](https://awesome-repositories.com/f/operating-systems-systems-programming/hardware-interfacing-drivers/hardware-acceleration/acceleration-detectors.md) — Identifies whether a graphics device uses hardware or software emulation to ensure the most efficient rendering path. ([source](https://developer.android.com/ndk/guides/graphics/design-notes))

### Development Tools & Productivity

- [Android NDK Configurations](https://awesome-repositories.com/f/development-tools-productivity/compilers-toolchains/cross-compilation-tooling/android-ndk-configurations.md) — Provides a collection of code examples demonstrating native code integration into Android applications. ([source](https://developer.android.com/ndk/guides/common-problems))
- [Native Binary Toolchains](https://awesome-repositories.com/f/development-tools-productivity/build-tooling/build-orchestration-logic/build-orchestration-configuration/build-automation-systems/build-systems/binary-compilation-toolchains/native-binary-toolchains.md) — Orchestrates the compilation of C and C++ source code into architecture-specific binaries using integrated build toolchains.
- [Cross-Compilation Toolchains](https://awesome-repositories.com/f/development-tools-productivity/cross-compilation-toolchains.md) — Configures build toolchains to compile native code for specific target architectures and platform versions. ([source](https://developer.android.com/ndk/guides/cmake))
- [CPU Profilers](https://awesome-repositories.com/f/development-tools-productivity/debugging-profiling-testing/debugging-diagnostics/performance-resource-profilers/cpu-profilers.md) — Calculates the percentage of CPU cycles consumed by specific shared libraries, functions, or threads to identify performance bottlenecks. ([source](https://developer.android.com/ndk/guides/simpleperf))
- [Runtime Version Queries](https://awesome-repositories.com/f/development-tools-productivity/development-environment-management/environment-provisioning-configuration/android-sdk-managers/runtime-version-queries.md) — Android NDK retrieves the target application SDK version and the current device API level at runtime to adjust native code behavior dynamically. ([source](https://developer.android.com/ndk/guides/sdk-versions))
- [Native Stack Unwinders](https://awesome-repositories.com/f/development-tools-productivity/dynamic-variable-evaluators/stack-frame-inspectors/native-stack-unwinders.md) — Translates raw memory addresses in crash logs into human-readable source code file names and line numbers. ([source](https://developer.android.com/ndk/guides/ndk-stack))
- [Native Compilation](https://awesome-repositories.com/f/development-tools-productivity/native-compilation.md) — Integrates C and C++ source files into the application build process to produce executable native libraries. ([source](https://developer.android.com/ndk/guides/build))

### System Administration & Monitoring

- [Corruption Detectors](https://awesome-repositories.com/f/system-administration-monitoring/memory-usage-analyzers/memory-allocation-debuggers/corruption-detectors.md) — Identifies native code errors including buffer overflows, use-after-free, and double-free vulnerabilities by instrumenting memory allocations. ([source](https://developer.android.com/ndk/guides/arm-mte))
- [Crash Reporters](https://awesome-repositories.com/f/system-administration-monitoring/diagnostic-tools/diagnostics/failure-analysis-tools/crash-reporters.md) — Captures serialized tombstone data from native crashes to enable post-mortem analysis of application failures. ([source](https://developer.android.com/ndk/guides/debug))

### Testing & Quality Assurance

- [Memory Leak Detection](https://awesome-repositories.com/f/testing-quality-assurance/debugging-diagnostics/memory-leak-detection.md) — Identifies memory corruption and invalid access patterns in native code using high-performance hardware-assisted or software-based sanitization tools. ([source](https://developer.android.com/ndk/guides/debug))

### Data & Databases

- [Memory Allocation Selectors](https://awesome-repositories.com/f/data-databases/memory-optimization-strategies/memory-allocation-selectors.md) — Evaluates device memory properties to choose the most efficient allocation strategy for buffers and images. ([source](https://developer.android.com/ndk/guides/graphics/design-notes))
- [Shared Memory Buffers](https://awesome-repositories.com/f/data-databases/shared-memory-buffers.md) — Shares raw memory regions between managed and native layers to eliminate expensive data copying.
- [Production Heap Monitors](https://awesome-repositories.com/f/data-databases/in-memory-databases/in-memory-state-stores/heap-inspection-tools/production-heap-monitors.md) — Samples memory allocations in production environments to identify heap-based corruption issues with minimal performance impact. ([source](https://developer.android.com/ndk/guides/memory-debug))

### Security & Cryptography

- [Secure Execution Environments](https://awesome-repositories.com/f/security-cryptography/secure-execution-environments.md) — Defends against memory-based attack vectors using hardware-level protection features on supported processors. ([source](https://developer.android.com/ndk/guides/abis))
- [Vulnerability Mitigation](https://awesome-repositories.com/f/security-cryptography/security/offensive-operations/vulnerability-research-analysis/vulnerability-mitigation.md) — Enables hardware-based pointer authentication and branch target identification to protect native code execution flow. ([source](https://developer.android.com/ndk/guides/memory-debug))

### DevOps & Infrastructure

- [Android Packages](https://awesome-repositories.com/f/devops-infrastructure/distribution-packaging/software-distribution/application-packaging/android-packages.md) — Distributes native code within AAR files to simplify integration for downstream developers. ([source](https://developer.android.com/ndk/guides/middleware-vendors))
- [Validation Layers](https://awesome-repositories.com/f/devops-infrastructure/distribution-packaging/software-distribution/application-packaging/android-packages/validation-layers.md) — Bundles validation binaries within application packages to ensure consistent graphics API verification across target devices. ([source](https://developer.android.com/ndk/guides/graphics/validation-layer))
- [Package Distribution](https://awesome-repositories.com/f/devops-infrastructure/package-distribution.md) — Packages multiple architecture-specific binaries and manages their extraction for target devices. ([source](https://developer.android.com/ndk/guides/abis))

### Hardware & IoT

- [MIDI Data Exchange](https://awesome-repositories.com/f/hardware-iot/integration-performance/hardware-interfacing-integration/hardware-interfacing/midi-and-osc-interfaces/midi-processing-engines/midi-data-exchange.md) — Enables sending and receiving MIDI messages directly within native code to minimize latency. ([source](https://developer.android.com/ndk/guides/audio/midi))

### Scientific & Mathematical Computing

- [Graph Construction Engines](https://awesome-repositories.com/f/scientific-mathematical-computing/data-modeling-processing/computational-graphs/graph-construction-engines.md) — Defines computation sequences of mathematical operations to represent complex machine learning models for runtime evaluation. ([source](https://developer.android.com/ndk/guides/neuralnetworks))
