Despite having Java and Kotlin for developing applications in Android, often we need to use C/C++ to write part of our application. Specially, when you want to ensure extra performance from your Android device then C/C++ codes will be the rescue. Because while programming in native code, the source is compiled directly into the machine code for the CPU and not into an intermediate language as Java does. To compile that C/C++ code we require NDK (Native Development Kit) bundle from Android SDK package. According to the official documentation:

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input

Unlike the unified Gradle build system for Java and Kotlin codes, we have multiple build tools for C/C++ codes. The default one recommended by Android is CMake, and other most supported build tool is ndk-build.

Why CMake?
Because Google recommended it! Apart from the joke, the ndk-build tool is more or less deprecated and still supported by Android just because of old legacy projects running into it. So if you are building something new, CMake will be the best choice to start. CMake’s main advantage is that you can use one set of build files for all your targets (Android, Linux, Windows, iOS, etc).

How does it work?
CMake is an external build tool that works alongside Gradle to build your native code and it requires a build script CMakeLists.txt to complete the build process. The CMake build script includes commands CMake uses to build your C/C++ sources and libraries. For new projects, Android Studio automatically creates an initial CMakeLists.txt build script and places it in your module’s root directory.