OpenCV for Android: Cannot find your ndk root directory!
- July 30th, 2011
- By AMB
- Write comment
Attention Conversation Notice: This problem can be solved by changing the line which reads -
set(NDK_ROOT "$ENV{HOME}/android-ndk-r4-crystax" CACHE STRING "the crystax ndk directory")
– to whatever your actual Android NDK directory is. (In my revision of the CMakesList.txt, the above line is line 53, but that may not hold for all revisions.)
So I’m working on a project for which I want to use OpenCV for Android. But when building one of the older revisions that is CMake compatible (following tutorial here) I ran into a problem where CMake spat out the following error:
So I updated $NDK_ROOT in my .bashrc and resourced. Ran CMake again, ran into the same problem. I messed with the path a bit, moved my NDK to a path without spaces, messed with quotes and escape characters in .bashrc, etc.
Then I opened up the CMakeLists.txt file and found this lovely little piece of bullshit:
set(NDK_ROOT "$ENV{HOME}/android-ndk-r4-crystax" CACHE STRING "the crystax ndk directory") if(NOT EXISTS ${NDK_ROOT}) message(FATAL_ERROR "Cannot find your ndk root directory! please download and unzip the android ndk from crystax to the directory specified by NDK_ROOT You may download the crystax ndk from: http://www.crystax.net/android/ndk-r4.php" ) endif()
Yeah, CMakeLists.txt was redefining $NDK_ROOT right before checking if it pointed to a valid path. This means that if you didn’t read the mind of whoever put the CMakeLists file together and put the NDK right where they thought it should go, well then you were shit out of luck. It completely ignores the NDK_ROOT variable set at the system level, redefined it to be what the developers THOUGHT it should be, then died when that folder didn’t exist. Then in the error message, it implied to the user that their NDK_ROOT didn’t point to the right folder.
Which, in my case, it fucking well did, thank you kindly.
The script didn’t just ignore the user’s path, substituting it for a hard-coded one, it then lied to the user about what the issue was.
I hope whoever created this chunk of programmatic excreta is ashamed of themselves.

