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
path
required
Must be the first line of every
Android.mk file. Defines the location of source files in the development tree.string
required
The name of the module you want to build. Must be unique across all module names and not contain spaces.
string
Optional override for the generated file name. By default, the module name determines the output file name.
Source files
list
required
List of C/C++ source files to compile. Paths are relative to
LOCAL_PATH.string
File extensions for C++ source files. Default is
.cpp. Use this if your files use different extensions.Compilation flags
string
Compiler flags for C and C++ files. Use for optimization, warnings, and feature flags.
string
Compiler flags for C++ files only.
string
Compiler flags for C files only.
string
Assembler flags for assembly files.
Include paths and libraries
list
Additional include directories. Paths can be absolute or relative to NDK root.
list
Include paths to export to modules that depend on this one.
list
List of static libraries to link against. Reference other ndk-build modules by name.
List of shared libraries to link against.
list
Static libraries to link with
--whole-archive flag. All object files from the library are included.Linking flags
string
Linker flags to use when building shared libraries or executables.
string
System libraries to link against. Use the
-l prefix.boolean
Allow undefined symbols in shared libraries. Default is
false.Preprocessor definitions
string
Use
-D flags to define preprocessor macros.string
Compiler flags to export to dependent modules.
Module types
Each module must include one of these module type definitions: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
string
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.string
Android API level to target. Higher API levels provide more functionality but reduce compatibility.
Build configuration
string
Optimization level:
release or debug. Default is release unless APP_DEBUG is true.boolean
Build debuggable binaries with symbols. Set to
true or false.string
C/C++ compiler flags for all modules.
string
C++ compiler flags for all modules.
string
Linker flags for all modules.
STL configuration
string
C++ Standard Library to use. Options include
c++_shared, c++_static, none, or system.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
list
Explicit list of modules to build. If not specified, all modules are built.
path
Absolute path to the project root. Default is the parent of the
Application.mk directory.path
Path to the build script. Default is
$(APP_PROJECT_PATH)/jni/Android.mk.Advanced settings
boolean
Use shorter command lines for build commands. Useful on Windows. Default is
false.boolean
Use thin archives for static libraries. Reduces build size. Default is
false.string
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: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.