VTK android compilation fails to find OpenGL librairies


I’m currently trying to manually cross compile VTK for the arm64-v8a android ABI but the compilation process fails to find backend librairies (OpenGL for rendering). I tried many VTK versions (v8.2.0, v9.0.0, v7.1.0, …) in combination with multiples NDK versions (16.1.4, 21.1.6) and API levels (21 → 29) installed via Android Studio, it still struggling with message like:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
linked by target "vtkRenderingOpenGL2" in directory /home/charles/libs/vtk/Rendering/OpenGL2

I found that OPENGL_egl_LIBRARY is a cache variable usually set by find_package(OpenGL) of CMake (CMake find OpenGL). I suppose that it should normally by resolved as “ndk-root-platform-root-dir/arch-arm64/usr/lib/libEGL.so” but it never found it despite setting manually this variable.

I also test to compile vtk library directly with the termux application of my phone (Armor 3W, Android 9.0) from my desktop with an ssh session. I installed required compilation tools and it fails with the same message, again librairies seems to be at the right place in the file system (/system/lib64/libEGL.so).

I also noticed that CMake seems to find OpenGL but maybe in the wrong place (OPENGL_INCLUDE_DIR=/usr/include in the cmake cache file instead of prebuild headers of NDK?).

The Makefile producing the above error was obtained by setting the CMake variables with VTK 8.2.0:

Can someone tell me where am i wrong ?

Also is it possible to cross compile VTK with standart cmake parameters for cross compilation for Android as it is described in Cross compile for android with the ndk. It works well with OpenCV for example.


Hi again,

First, i understood that executing cmake with VTK_ANDROID_ BUILD option to ON simply call vtkAndroid.cmake which is just a superbuild wrapper to compile “compilation tools” first and then perform cross compilation of vtk with standard cmake parameters by taking top cmake parameters as arguments. However it offers less place for the developer to customize the compilation of vtk for android but it is easily by passable by manually build compiletools lib and perform cross compilation of vtk by hand.

Otherwise, i finally get vtk 8.2.0 compiled by using the r16b NDK but from scratch build directory ! If you try to change ANDROID_NDK after executing the first cmake command it doesn’t seems to be taken in account. For example the compilation with r21e NDK worked well once i get vtk compiled with r16b but i bet that cmake doesn’t update cache parameters used by r16b.

I will get interested to know why NDK revisions > 16 are not compatible, but for now the problem is solved.

Hi Charles,

With some recent commits, you should be able to build VTK for Android again.