android.toolchain.cmake) that configures CMake for cross-compilation.
Toolchain configuration
To use the Android toolchain, specify it when invoking CMake:Platform variables
These variables configure the target Android platform and architecture.string
required
Target Application Binary Interface (ABI). Determines the instruction set and calling conventions.
Supported ABI values
For new applications, target
arm64-v8a and x86_64. The armeabi, mips, and mips64 ABIs are deprecated and removed.string
required
Minimum Android API level to target. Determines available APIs and system libraries.
Android 5.0 (API 21) is the minimum supported version for 64-bit ABIs. Use API 21 or higher for modern applications.
path
Path to the Android NDK. Automatically set by Android Studio, but can be specified manually.
C++ configuration
CMake provides variables to configure the C++ standard library and language features.string
C++ Standard Library implementation to use. Default is
c++_shared.STL options
If using
c++_static, ensure all shared libraries in your app use the same STL to avoid violations of the One Definition Rule (ODR).integer
C++ language standard version. Common values:
11, 14, 17, 20.string
Additional C++ compiler flags.
string
Additional C compiler flags.
Compilation settings
string
ARM instruction set mode for 32-bit ARM builds:
arm (32-bit) or thumb (16-bit, default).boolean
Enable ARM NEON SIMD instructions for
armeabi-v7a. Default is TRUE.boolean
Disable compiler format string security checks. Default is
FALSE. Not recommended.path
Path to ccache executable for faster rebuilds.
Linking configuration
Linker flags for shared libraries.
string
Linker to use:
lld (default, recommended) or deprecated (old GNU linkers).The LLD linker is faster and produces smaller binaries. The deprecated GNU linkers (gold, bfd) are removed in newer NDK versions.
Library linking
Link Android system libraries usingtarget_link_libraries:
Common Android libraries
Complete CMakeLists.txt example
Build types
CMake supports different build configurations:string
Build configuration:
Debug, Release, RelWithDebInfo, or MinSizeRel.Architecture-specific code
Use CMake variables to conditionally compile architecture-specific code:Useful CMake variables
Finding and using libraries
Using find_library
Find system libraries at runtime:Importing prebuilt libraries
Using external projects
Gradle integration
Android Studio uses Gradle to invoke CMake. Configure CMake inbuild.gradle:
Gradle CMake arguments
Advanced configuration
Custom toolchain configuration
Strip symbols in release builds
Multiple ABI builds
For production apps, build for at least
arm64-v8a and armeabi-v7a to support both modern and older devices. The Play Store requires 64-bit support.