Android.mk (module definitions) and Application.mk (application-wide settings).
Android.mk variables
TheAndroid.mk file defines build modules and their properties. Each module describes a single library or executable.
Module definition
Must be the first line of every
Android.mk file. Defines the location of source files in the development tree.The name of the module you want to build. Must be unique across all module names and not contain spaces.
Optional override for the generated file name. By default, the module name determines the output file name.
Source files
List of C/C++ source files to compile. Paths are relative to
LOCAL_PATH.File extensions for C++ source files. Default is
.cpp. Use this if your files use different extensions.Compilation flags
Compiler flags for C and C++ files. Use for optimization, warnings, and feature flags.
Compiler flags for C++ files only.
Compiler flags for C files only.
Assembler flags for assembly files.
Include paths and libraries
Additional include directories. Paths can be absolute or relative to NDK root.
Include paths to export to modules that depend on this one.
List of static libraries to link against. Reference other ndk-build modules by name.
List of shared libraries to link against.
Static libraries to link with
--whole-archive flag. All object files from the library are included.Linking flags
Linker flags to use when building shared libraries or executables.
System libraries to link against. Use the
-l prefix.Allow undefined symbols in shared libraries. Default is
false.Preprocessor definitions
Use
-D flags to define preprocessor macros.Compiler flags to export to dependent modules.
Module types
Each module must include one of these module type definitions:| Module Type | Description | Usage |
|---|---|---|
BUILD_SHARED_LIBRARY | Builds a shared library (.so) | include $(BUILD_SHARED_LIBRARY) |
BUILD_STATIC_LIBRARY | Builds a static library (.a) | include $(BUILD_STATIC_LIBRARY) |
BUILD_EXECUTABLE | Builds a native executable | include $(BUILD_EXECUTABLE) |
PREBUILT_SHARED_LIBRARY | Uses a prebuilt shared library | include $(PREBUILT_SHARED_LIBRARY) |
PREBUILT_STATIC_LIBRARY | Uses a prebuilt static library | include $(PREBUILT_STATIC_LIBRARY) |
Complete Android.mk example
Application.mk variables
TheApplication.mk file describes application-wide settings. It’s optional and located in jni/Application.mk.
Platform and ABI configuration
Target ABIs to build for. Can specify multiple ABIs or use
all for all supported ABIs.Common ABI values:
armeabi-v7a, arm64-v8a, x86, x86_64. The armeabi and mips ABIs are deprecated.Android API level to target. Higher API levels provide more functionality but reduce compatibility.
Build configuration
Optimization level:
release or debug. Default is release unless APP_DEBUG is true.Build debuggable binaries with symbols. Set to
true or false.C/C++ compiler flags for all modules.
C++ compiler flags for all modules.
Linker flags for all modules.
STL configuration
C++ Standard Library to use. Options include
c++_shared, c++_static, none, or system.| STL Option | Description |
|---|---|
c++_shared | LLVM libc++ as shared library (recommended) |
c++_static | LLVM libc++ as static library |
none | No C++ standard library |
system | System C++ runtime (minimal, deprecated) |
Use
c++_shared for most applications. If you use c++_static, ensure all shared libraries use the same STL to avoid ODR violations.Module configuration
Explicit list of modules to build. If not specified, all modules are built.
Absolute path to the project root. Default is the parent of the
Application.mk directory.Path to the build script. Default is
$(APP_PROJECT_PATH)/jni/Android.mk.Advanced settings
Use shorter command lines for build commands. Useful on Windows. Default is
false.Use thin archives for static libraries. Reduces build size. Default is
false.Script to wrap build commands. Useful for build analysis tools.
Complete Application.mk example
Build system functions
The ndk-build system provides several helper functions:| Function | Description |
|---|---|
$(call my-dir) | Returns the directory of the current makefile |
$(call import-module,<name>) | Imports a module by name from NDK_MODULE_PATH |
$(call import-add-path,<path>) | Adds a path to the module search path |
Common build patterns
Building multiple modules
Using prebuilt libraries
Conditional compilation
For new projects, consider using CMake instead of ndk-build. CMake offers better IDE integration and is the recommended build system for Android native development.