Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running CMake from command line within an Android NDK project

How might one run an NDK Cmake build independently from the rest of an Android project, ideally from the command line, external to Android Studio?

The equivalent of running ndk-build from the jni directory for slightly older Android NDK projects.

I need to investigate exactly what the calls to the compiler look like, and I can't seem to get this information when building the whole project from within Android Studio

My first attempt was just to run cmake from the project/app directory containing CMakeLists.txt, but this informs me that cmake is not installed - so how is Android Studio managing to build it then?

like image 600
bph Avatar asked Jun 21 '17 09:06

bph


People also ask

How do I run CMake from terminal?

Running CMake from the command line To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project. The process stops when there are no longer any more questions to ask.

What is NDK and CMake?

The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. 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.


1 Answers

If your goal is to just run from the command line (as opposed to trying to do exactly what gradle is doing), just use cmake the way you normally would:

$ cmake -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
    -DANDROID_ABI=whatever $YOUR_SOURCE_DIR

Alternatively, you can just run ./gradlew from the command line.

like image 158
Dan Albert Avatar answered Sep 22 '22 13:09

Dan Albert