Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between CMake and NDK-build in android studio project

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?

like image 286
0xAliHn Avatar asked Sep 20 '16 08:09

0xAliHn


People also ask

What is CMake used for in Android Studio?

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. LLDB: the debugger Android Studio uses to debug native code. By default, LLDB will be installed alongside Android Studio.

What is NDK build?

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.

What is CMake used for?

CMake is an open-source, cross-platform tool that uses compiler and platform independent configuration files to generate native build tool files specific to your compiler and platform. The CMake Tools extension integrates Visual Studio Code and CMake to make it easy to configure, build, and debug your C++ project.

Does CMake support android?

The Android NDK supports using CMake to compile C and C++ code for your application. This page discusses how to use CMake with the NDK via the Android Gradle Plugin's ExternalNativeBuild or when invoking CMake directly.


1 Answers

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.

like image 118
Dan Albert Avatar answered Sep 28 '22 09:09

Dan Albert