Running CMake from command line in Android NDK project

How can the NDK Cmake build be run independently of the rest of the Android project, ideally from a command line external to Android Studio?

Equivalent to running ndk-build

from jni directory for older Android NDK projects.

I need to figure out exactly what the compiler calls look like and I cannot get this information when building the whole project from Android Studio

My first attempt was to run cmake from the project/app

containing directory , CMakeLists.txt

but that tells me cmake

not installed - so how does Android Studio manage to create it?

+5


source to share


3 answers


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

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

      



Alternatively, you can simply run ./gradlew

from the command line.

+10


source


The original problem is that you don't see the command line invocation when building with Android Studio.

You can get command line arguments to the compiler by editing the app / build.gradle file.

defaultConfig {
    ...
    externalNativeBuild {
        cmake {
            ...
            arguments "-DCMAKE_VERBOSE_MAKEFILE=1", ...
        }
    }

}

      



In the Adroid Studio Gradle console pane, you will see the command line for the compiler and linker as follows:

[1/176] / home / bram / android-sdk-linux / ndk-bundle / toolchains / llvm / prebuilt / linux-x86_64 / bin / clang --target = armv7-none-linux-androideabi --gcc -toolchain = /home/bram/android-sdk-linux/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot = / home / bram / android-sdk-linux / ndk- bundle / sysroot -isystem / home / bram / android-sdk-linux / ndk-bundle / sysroot / usr / include / arm-linux-androideabi -D__ANDROID_API __ = 19 -g -DANDROID -section-functions -funwind-tables -fstack- protector- strong -no-canonical-prefixes -march = armv7-a -mfloat-abi = softfp -mfpu = vfpv3-d16 -fno-integrated-as -marm -mfpu = neon -Wa, -noexecstack -Wformat -Werror = format-security -Os -DNDEBUG -fPIC -MD -MT / home / bram / src / GPGOAP / CMakeFiles / gpgoap.dir / astar.co -MF / home / bram / src / GPGOAP / CMakeFiles / gpgoap.dir / astar. cod -o / home / bram / src / GPGOAP / CMakeFiles / gpgoap.dir / astar.co -c / home / bram / src / GPGOAP / astar.c

+5


source


As detailed to the accepted answer:

The complete set of parameters passed to CMake is written in:

<project-root>/<module-root>/.externalNativeBuild/cmake/<build-type>/<ABI>/cmake_build_command.txt'

      

See: https://developer.android.com/ndk/guides/cmake.html#build-command for details .

0


source







All Articles