Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

c++ - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...