The Android NDK provides multiple build system options for compiling native code. Understanding the differences helps you choose the right tool for your project.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/android/ndk/llms.txt
Use this file to discover all available pages before exploring further.
Available build systems
The NDK supports two primary build systems:ndk-build
Traditional NDK build system using Android.mk files
CMake
Cross-platform build system with modern syntax
Comparison
- ndk-build
- CMake
Pros:
- Simple syntax for Android-specific builds
- Direct NDK integration with built-in variables
- Smaller learning curve for simple projects
- Extensive documentation and examples
- Android-specific, not portable to other platforms
- Limited functionality compared to CMake
- Based on GNU Make syntax
- Less flexible for complex build configurations
- Android-only projects
- Simple native libraries
- Legacy codebases using Android.mk
Choosing a build system
Use this decision tree to select the appropriate build system:Evaluate portability needs
If your native code needs to run on multiple platforms (iOS, desktop, etc.), choose CMake for cross-platform compatibility.
Consider existing codebase
If you have existing Android.mk files or a legacy ndk-build setup, you can continue using ndk-build or migrate to CMake.
Assess complexity
For simple Android-only libraries with straightforward build requirements, ndk-build may be sufficient. For complex dependencies and build configurations, CMake provides more flexibility.
Google recommends CMake for new projects due to its cross-platform nature and industry-standard tooling.
Build system features
Module support
Both build systems support building multiple native modules:- Static libraries (.a) - Linked at compile time
- Shared libraries (.so) - Loaded at runtime
- Executables - For command-line tools
ABI management
Both systems can target multiple Android ABIs:Compiler flags and optimizations
Both systems allow you to customize:- Compiler flags (warnings, optimizations)
- Preprocessor definitions
- Include paths
- Linker flags and library dependencies
Integration with Gradle
Both build systems integrate with the Android Gradle Plugin through theexternalNativeBuild configuration:
- ndk-build
- CMake
build.gradle
Migration between systems
You can migrate from ndk-build to CMake when needed:Convert module definitions
Transform Android.mk module definitions into CMakeLists.txt targets using
add_library() commands.Map variables
Convert NDK-specific variables to CMake equivalents. For example,
LOCAL_SRC_FILES becomes the source list in add_library().Update dependencies
Convert
LOCAL_SHARED_LIBRARIES and LOCAL_STATIC_LIBRARIES to target_link_libraries() calls.Update Gradle configuration
Change
externalNativeBuild.ndkBuild to externalNativeBuild.cmake in your build.gradle file.Next steps
Using ndk-build
Learn about Android.mk and Application.mk files
Using CMake
Configure CMake for Android NDK projects
Gradle integration
Integrate native builds with Android Gradle
ABIs
Understand Android binary interfaces