# VTK for Android

**URL:** https://discourse.vtk.org/t/vtk-for-android/5604
**Category:** Development
**Created:** [April 21, 2021, 5:04pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604 "2021-04-21T17:04:01Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![timt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/timt/32/3018_2.png) [@timt](https://discourse.vtk.org/u/timt)
#### Post date: [April 21, 2021, 5:04pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/1 "2021-04-21T17:04:01Z")

</div>

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

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

```

I have tried the following NDKs:

```auto
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:

```auto
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](https://discourse.vtk.org/t/vtk-android-compilation-fails-to-find-opengl-librairies/5443) seems to suggest that NDK version r16b should work with VTK v8.0.2. However, with this configuration, I am getting the following error:

```auto
/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 want to use VTK on Android.](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945)
- [Android NDK newer than r18 fails to compile](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310)
- [Cross Compiling VTK for Mobile Architectures](https://discourse.vtk.org/t/cross-compiling-vtk-for-mobile-architectures/5193)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 21, 2021, 5:11pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/2 "2021-04-21T17:11:07Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![timt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/timt/32/3018_2.png) [@timt](https://discourse.vtk.org/u/timt)
#### Post date: [April 21, 2021, 5:32pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/3 "2021-04-21T17:32:08Z")

</div>

Adding `#include <numerics>` generates a subsequent error:

```auto
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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 21, 2021, 5:50pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/4 "2021-04-21T17:50:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![timt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/timt/32/3018_2.png) [@timt](https://discourse.vtk.org/u/timt)
#### Post date: [April 21, 2021, 6:29pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/5 "2021-04-21T18:29:39Z")

</div>

This is an earlier version of the NDK:

> [@timt](#):
>
> [This post](https://discourse.vtk.org/t/vtk-android-compilation-fails-to-find-opengl-librairies/5443) seems to suggest that NDK version r16b should work with VTK v8.0.2.

---

<div class="post-metadata">

### Author: ![Charles](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles/32/3181_2.png) [@Charles](https://discourse.vtk.org/u/Charles)
#### Post date: [April 21, 2021, 10:41pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/6 "2021-04-21T22:41:39Z")

</div>

Hi,

i’m the author of [the post](https://discourse.vtk.org/t/vtk-android-compilation-fails-to-find-opengl-librairies/5443) 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.

---

<div class="post-metadata">

### Author: ![Joachim\_P](https://discourse.vtk.org/user_avatar/discourse.vtk.org/joachim_p/32/3272_2.png) [@Joachim\_P](https://discourse.vtk.org/u/Joachim_P)
#### Post date: [July 8, 2021, 5:00am UTC](https://discourse.vtk.org/t/vtk-for-android/5604/7 "2021-07-08T05:00:16Z")

</div>

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

Joachim

---

<div class="post-metadata">

### Author: ![timt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/timt/32/3018_2.png) [@timt](https://discourse.vtk.org/u/timt)
#### Post date: [July 27, 2021, 3:08pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/8 "2021-07-27T15:08:30Z")

</div>

Just updating here that the recent changes in [!8163](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8163) once again allow VTK to be build for Android.

---

<div class="post-metadata">

### Author: ![perphy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/p/958977/32.png) [@perphy](https://discourse.vtk.org/u/perphy)
#### Post date: [November 24, 2022, 2:14pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/9 "2022-11-24T14:14:34Z")

</div>

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”

 ![terminal](https://discourse.vtk.org/uploads/default/original/2X/4/4c154190e6422aa572f7ba1486a4c6509e656c07.png)  
In attachment “CMakeOutput”, it seems that OFF\_T\_64 is not big enough, cause it return value 1.  
 ![CMakeOutput](https://discourse.vtk.org/uploads/default/original/2X/a/ac36868bacfe0c3ff0505f17f8173239f7a3e04b.png)

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

 ![build make](https://discourse.vtk.org/uploads/default/original/2X/7/7113d32ff6cc637a1ff439a54c0c99e88c19f4bf.png)

Here is other two related screen shots.

 ![CmakeList](https://discourse.vtk.org/uploads/default/original/2X/4/455253321668f44c9fbb10a931ea8f4c4f8aac02.png)

 ![vtkModule](https://discourse.vtk.org/uploads/default/original/2X/c/cd2d287f71d1d39ce57f5af90878e08d28e17a20.png)  
Thanks very much

---

<div class="post-metadata">

### Author: ![timt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/timt/32/3018_2.png) [@timt](https://discourse.vtk.org/u/timt)
#### Post date: [December 16, 2022, 2:47pm UTC](https://discourse.vtk.org/t/vtk-for-android/5604/10 "2022-12-16T14:47:02Z")

</div>

Hello,

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

```auto
$ 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

---

<div class="post-metadata">

### Author: ![Q1CHEN](https://discourse.vtk.org/user_avatar/discourse.vtk.org/q1chen/32/6435_2.png) [@Q1CHEN](https://discourse.vtk.org/u/Q1CHEN)
#### Post date: [January 18, 2023, 12:15am UTC](https://discourse.vtk.org/t/vtk-for-android/5604/11 "2023-01-18T00:15:00Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/-/tree/master/Examples/Android)  
I appreciate any help 🙂
