What is the actual difference between CMake
and NDK
build in android studio project. I already went through google documentation but the concept is not clear yet. As per google documentation:
The Android Native Development Kit (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access the physical device components, such as sensors and touch input.
CMake: an external build tool that works alongside Gradle to build your native library. You do not need this component if you only plan to use ndk-build.
Can anyone has a better explanation with an example when we need to use what?
To clear up some confusion here: ndk-build is a build system included in the NDK. It uses Android.mk
files. The NDK itself is a collection of compilers and libraries that are needed to build C/C++ code for Android. ndk-build and cmake both use the NDK.
What is the actual difference between CMake and NDK build in android studio project.
They use a different language (custom makefiles vs cmake) to describe builds. Ideally there is no difference in output for identically described builds, but that doesn't mean there aren't any bugs.
Can anyone has a better explanation with an example when we need to use what?
In general, use whichever system you prefer.
CMake's main advantage is that you can use one set of build files for all your targets (Android, Linux, Windows, iOS, etc). If your project is cross platform, CMake should make that easiest on you. It also is widely known outside Android developers, so people new to Android will have a better chance of understanding it.
ndk-build should be preferred if you're building a project that already uses Android.mk
files for its build system (legacy projects).
If you're writing new code, use whatever you're comfortable with. If you're not familiar with either, cmake is probably the better choice because it will make cross-platform work easier in the future if you choose to do so.