# Android NDK r23 with CMake 3.21 or later

**URL:** https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577
**Category:** Development
**Tags:** os:android
**Created:** [December 1, 2021, 11:02am UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577 "2021-12-01T11:02:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 1, 2021, 11:02am UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/1 "2021-12-01T11:02:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 1, 2021, 11:09am UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/2 "2021-12-01T11:09:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 1, 2021, 12:02pm UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/3 "2021-12-01T12:02:16Z")

</div>

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:

- ANDROID\_NATIVE\_LIB\_DEPENDENCIES
- ANDROID\_NATIVE\_LIB\_DIRECTORIES
- ANDROID\_JAVA\_SOURCE\_DIR
- ANDROID\_JAR\_DIRECTORIES
- ANDROID\_JAR\_DEPENDENCIES
- ANDROID\_ASSETS\_DIRECTORIES
- ANDROID\_PROCESS\_MAX
- ANDROID\_PROGUARD
- ANDROID\_PROGUARD\_CONFIG\_PATH
- ANDROID\_SECURE\_PROPS\_PATH
- ANDROID\_SKIP\_ANT\_STEP
- ANDROID\_ANT\_ADDITIONAL\_OPTIONS

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?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [December 1, 2021, 3:24pm UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/4 "2021-12-01T15:24:12Z")

</div>

> that is not where the platforms directory is located

Maybe something changed in NDK versions since that was written.

> [@craig.scott](#):
>
> I’m using an Android Studio installation on macOS for reference

All the existing support and documentation was developed using the NDKs found on the [Android NDK download page](https://developer.android.com/ndk/downloads). Please check those versions too.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [December 1, 2021, 3:26pm UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/5 "2021-12-01T15:26:14Z")

</div>

> [@craig.scott](#):
>
> is the NVIDIA Nsight Tegra setup still even used or maintained

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.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 4, 2021, 10:33am UTC](https://discourse.cmake.org/t/android-ndk-r23-with-cmake-3-21-or-later/4577/6 "2021-12-04T10:33:22Z")

</div>

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):

> <https://github.com/android/ndk/issues/1618>
>
> \#### Description
> 
> The NDK's CMake toolchain file sets a variable named \`CMAKE\_…ANDROID\_EXCEPTION\`, but it should be \[\`CMAKE\_ANDROID\_EXCEPTIONS\`\](https://cmake.org/cmake/help/v3.22/variable/CMAKE\_ANDROID\_EXCEPTIONS.html) (note the plural rather than singular). This variable will therefore have no effect when CMake is deciding whether to add \`-fexceptions\` or \`-fno-exceptions\` to the \`CMAKE\_\<LANG\>\_FLAGS\_INIT\` flags, resulting in the flag being determined purely based on the selected STL type. This only affects build arrangements where \`ANDROID\_CPP\_FEATURES\` is set (I'm not sure what situations do that).
> 
> \#### Environment Details
> 
> Found while working on macOS on an M1 machine. NDK 23.1.7779620 was installed via Android Studio, but the toolchain file from a standalone NDK package (r24-beta1) still has the same problem.

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.
