[question] How do you set the NDK path for Android builds in CMakeToolchain?
See original GitHub issueI’m trying to figure out how to build for Android using the Conan 2.0 CMakeToolchain. I get this error:
ConanException: CMakeToolchain needs tools.android:ndk_path configuration defined
The docs mention tools.android:ndk_path, but not how to set it. There are a few clues in the source code, but all the things I’ve tried in conanfile.py and conan.conf haven’t worked. This was very easy with the cmake generator, I just did this:
cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = os.getenv("ANDROID_NDK_ROOT") + "/build/cmake/android.toolchain.cmake"
…but it doesn’t work anymore.
Currently, I share this Python script with my Conan 1.x packages to define build settings for desktop and mobile platform builds: https://github.com/ssrobins/conan-cmake_utils/blob/217df94/cmake_utils.py.
In addition to being stuck on this, I’m a bit concerned that Conan 2.0 will make it not possible or at least harder to use custom toolchains, which is critical for close-sourced platforms that don’t have any built-in CMake support.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)

Top Related StackOverflow Question
Thanks @memsharded, putting that code in
~/.conan/profiles/defaultallowed NDK to be found. Unfortunately, it failed right after with:I tried adding
ANDROID_STLandCMAKE_MAKE_PROGRAM, even thoughninjais in myPATHand is working in non-Conan 2.0 packages, but it didn’t help. Here’s my fullgenerate()method:The
CMAKE_OSX_DEPLOYMENT_TARGETfor macOS and iOS are working so this seems to only affect the Android builds.For Conan 1.x, this is all I had to add to my
conanfile.pyto build Android:I was just able to pass CMake params exactly how it would work without Conan. Yes it’s more code than if it was taken care of for me, but I appreciated the transparency and simplicity. It let me use the
ANDROID_NDK_ROOTenvironment variable as the single definition for NDK on my system that works for CMake and Conan 1.x. It’s also starting to become the standard in cloud CI environments like GitHub Actions.For the Android toolchain as well as any custom toolchain, I would love for this to be done with a setting in the conanfile.py, like it was before. The
cmakeinterface is excellent in Conan 1.x, I don’t understand why it’s being made less discoverable and spread to multiple files for Conan 2.x.Just created a new one from your comment in https://github.com/conan-io/conan/issues/9282, please track it and provide feedback there. Thanks!