cmake does not find libraries when compiling for Android

I’ve just today discovered that its surprisingly simple to compile c++ projects with cmake for Android. I use Ubuntu Linux as a host, with the latest NDK. The build worked smoothly for a whole number of standard libraries (zlib, bzip2, Zstandard, and a few others)!

I’ve used the following parameters (I guess some of these are not even required, but I add them for completeness):


Now, while the build works, the find scripts from cmake seem not to work! Since the same build settings work on the host computer (just removing the Android specifics), I assume all paths etc should be correct.

For example, when building pcre2, it complains that bzip2 can not be found, even though its compiled and installed with cmake (including a package configuration). Similarly, when building Qt, it will not find bzip2, Zstandard and OpenSSL.

Is there something special needed when cross-compiling, or when building for Android?

I’m using cmake version 3.22.2-g45390d0 that I build from sources, and Ninja 1.10.2 also built from sources.

Ok, I’ve found the solution a few hours later. This should definitely be better documented, or maybe cmake could even help isolate the problem. The helpful discussion is in The Android NDK cmake toolchain overrides CMAKE_FIND_ROOT_PATH.

I did not consider that there is such a variable that makes cmake essentially ignore CMAKE_PREFIX_PATH? I think it would be very helpful if cmake would warn when CMAKE_PREFIX_PATH points outside of CMAKE_FIND_ROOT_PATH.

Posting issue link for completeness

I am also facing same issue, how did you solve ?

@Praveen_CK , the solution for me was to put all paths from CMAKE_PREFIX_PATH also in CMAKE_FIND_ROOT_PATH, then it worked.

For me that boils down to something like:

cmake \