VTK for Android

I am currently trying to build any recent version of VTK with any recent version of Android using:

cmake -S vtk -B vtk-android-build -GNinja -DVTK_ANDROID_BUILD=ON
cmake --build vtk-android-build

I have tried the following NDKs:

android-ndk-r21e
android-ndk-r19c
android-ndk-r16b

Along with the three v8.0.2 tags as well as the current master for VTK with each of these.

For most Cartesian products, I am consistently getting the error:

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:
OPENGL_egl_LIBRARY
    linked by target "vtkRenderingOpenGL2" in directory /home/tt/kw/vtk/Rendering/OpenGL2

This post seems to suggest that NDK version r16b should work with VTK v8.0.2. However, with this configuration, I am getting the following error:

/home/tt/kw/vtk/Common/System/vtkTimerLog.cxx: In static member function 'static void vtkTimerLog::DumpLogWithIndentsAndPercentages(std::ostream*)':
/home/tt/kw/vtk/Common/System/vtkTimerLog.cxx:536:25: error: 'round' is not a member of 'std'
     double percentage = std::round(elapsedTime / parent.second * 1000.) / 10.;

Is there a known build/NDK/SDK configuration that works?

See also:

I suspect the std::round is due to a missing <numeric> include directive.

master doesn’t seem to use OPENGL_egl_LIBRARY anymore (though there are some vestiges in vtkMobileDevices.cmake setting it, I don’t use uses of it).

Adding #include <numerics> generates a subsequent error:

In file included from /home/tt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/fstream:41:0,
                 from /home/tt/kw/vtk/Common/Core/vtkIOStream.h:32,
                 from /home/tt/kw/vtk/Common/Core/vtkSystemIncludes.h:39,
                 from /home/tt/kw/vtk/Common/Core/vtkIndent.h:28,
                 from /home/tt/kw/vtk/Common/Core/vtkObjectBase.h:52,
                 from /home/tt/kw/vtk/Common/Core/vtkObject.h:45,
                 from /home/tt/kw/vtk/Common/Core/vtkAbstractArray.h:61,
                 from /home/tt/kw/vtk/Common/Core/vtkAbstractArray.cxx:15:
/home/tt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:107:11: error: '::fgetpos' has not been declared
   using ::fgetpos;

I’m guessing this build hasn’t been used or tested in awhile?

Yeah, it would seem so. Isn’t the NDK supposed to be using libc++ these days though?

This is an earlier version of the NDK:

Hi,

i’m the author of the post you mentioned, build VTK with recent versions of NDK is still messy but i have retried it because NDK r16b was too old to be used for my own code and others dependencies.

I found another workaround to get VTK compiled with NDK r21e but this time without backend librairies if you don’t need to render things and use only others common functions. Here is the portion of my documentation with instructions:

# Install VTK (8.2.0) from sources
cd ~/libs
git clone https://github.com/Kitware/VTK.git
cd VTK
git checkout v8.2.0
# Manually disable those backend modules in CMake/vtkAndroid.cmake
# -DModule_vtkInteractionStyle:BOOL=OFF
# -DModule_vtkRenderingCore:BOOL=OFF
# -DModule_vtkRenderingFreeType:BOOL=OFF
# -DModule_vtkTestingRendering:BOOL=OFF
# -DModule_vtkRenderingVolumeOpenGL2:BOOL=OFF
mkdir build && cd build
cmake .. \
-DVTK_ANDROID_BUILD=ON \
-DANDROID_NDK=$ANDROID_NDK_PATH \
-DANDROID_NATIVE_API_LEVEL=28 \ 
-DANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_BUILD_TYPE=Release
make -j8
cp -r CMakeExternals/Install/vtk-android/* $ANDROID_ARM64_V8A_INSTALL_PREFIX

But i don’t giving up to make thoses backend librairies found by linker with recent NDK versions.

I hope this can help you.

For info, I am currently working on it. See https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8163
Still facing issues with some math functions (isnan, isfinite, etc).

Joachim

Just updating here that the recent changes in !8163 once again allow VTK to be build for Android.

1 Like

Hi:

I am trying to build vtk on android by ves

I use:

ubuntu 22.4

gcc 10.4

vtk9.2.2 (I change the url on vtksuperbuild.cmake)

after run

make -j4

I meet the problem as shown in attachment "terminal”


In attachment “CMakeOutput”, it seems that OFF_T_64 is not big enough, cause it return value 1.

It seems that the error occur in attachment “build.make” line 92,

Here is other two related screen shots.


Thanks very much

Hello,

We no longer support VES. You can build VTK directly for Android now using something like the following:

$ ccmake -DVTK_ANDROID_BUILD=ON \
         -DANDROID_NDK=/path/to/android-ndk-r21e/ \
         -DANDROID_NATIVE_API_LEVEL=27 \
         -DANDROID_ARCH_ABI=arm64-v8a \
         ../vtk

Please see the previous comments and PRs mentioned above.

Thanks,
TT

Hi, I built vtk-android from source but I can not find any apk files that I can intall onto my phone…
In the end of this official readme file indicates that there should be some apks after build.
https://gitlab.kitware.com/vtk/vtk/-/tree/master/Examples/Android
I appreciate any help :slight_smile: