Android NDK r23 with CMake 3.21 or later

I’m working through building for Android, specifically with NDK r23. From that NDK release, we should be back to a fully supported arrangement again if we are using CMake 3.21 or later. I want to record here things I find that still seem to be not in sync, docs that need updating around this, etc. The discussion thread may end up a bit disjointed, but I need somewhere to collect questions, discuss and record findings.

Docs for CMAKE_ANDROID_NDK state the following:

When Cross Compiling for Android with the NDK, this variable holds the absolute path to the root directory of the NDK. The directory must contain a platforms subdirectory holding the android-<api> directories.

Looking at what the NDK’s toolchain sets this to though, this is not true. While the value is set to the root of the NDK, that is not where the platforms directory is located. The platforms directory is actually two more levels up, under the sdk directory (I’m using an Android Studio installation on macOS for reference). The build seems to work without any warnings, so I’m wondering if the second sentence in the above is no longer true?

A number of Android-specific properties appear to only be used by some scenarios, but the docs don’t mention this. For example, (at least) the following target properties seem to only be used in the Visual Studio generator, so presumably they only apply to the NVIDA Nsight Tegra setup:


For someone using just the NDK exclusively, it may not be immediately obvious that none of the above properties are relevant or used. Their documentation should at least be updated to specify under what conditions they are used. Other Android-related properties do generally indicate whether they are intended for the NVIDIA Nsight Tegra setup, or the NDK, or both (or their name makes it obvious).

Out of interest, is the NVIDIA Nsight Tegra setup still even used or maintained?

that is not where the platforms directory is located

Maybe something changed in NDK versions since that was written.

All the existing support and documentation was developed using the NDKs found on the Android NDK download page. Please check those versions too.

AFAIK it is not tested or maintained, but I also don’t know for sure that it is broken or unused.

The Nsight Tegra mode was added before the rest of the Android support, so at the time those variables were documented such context was not needed. Appropriate notes could be added to those variables’ documentation now though.

Posting this here for visibility. If using ANDROID_CPP_FEATURES to control whether to use rtti and/or exceptions, please be aware of the following bug present in NDK r23 (also still present in NDK r24-beta1):

That bug means the default value of CMAKE_ANDROID_EXCEPTIONS is always determined by the choice of STL, which for the two main ones still supported by NDK r23 (c++_shared and c++_static) means exceptions will be enabled.