# I want to use VTK on Android.

**URL:** https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945
**Category:** Support
**Created:** [May 10, 2019, 7:57am UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945 "2019-05-10T07:57:59Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ruanwenfeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ruanwenfeng/32/394_2.png) [@ruanwenfeng](https://discourse.vtk.org/u/ruanwenfeng)
#### Post date: [May 10, 2019, 7:57am UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/1 "2019-05-10T07:57:59Z")

</div>

[10/1033] Building CXX object IO/Export/CMakeFiles/vtkIOExport.dir/vtkGL2PSExporter.cxx.o  
FAILED: IO/Export/CMakeFiles/vtkIOExport.dir/vtkGL2PSExporter.cxx.o  
D:\Android\ndk-bundle\toolchains\llvm\prebuilt\windows-x86\_64\bin\clang++.exe --target=armv7-none-linux-androideabi28 --gcc-toolchain=D:/Android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86\_64 --sysroot=D:/Android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86\_64/sysroot -DVTK\_IN\_VTK -IIO/Export -I…/IO/Export -ICommon/Core -I…/Common/Core -IUtilities/KWIML -I…/Utilities/KWIML -IUtilities/KWSys -I…/Utilities/KWSys -IThirdParty/utf8 -I…/ThirdParty/utf8 -ICommon/DataModel -I…/Common/DataModel -ICommon/Math -I…/Common/Math -ICommon/Misc -I…/Common/Misc -ICommon/System -I…/Common/System -ICommon/Transforms -I…/Common/Transforms -IFilters/Geometry -I…/Filters/Geometry -ICommon/ExecutionModel -I…/Common/ExecutionModel -IFilters/Core -I…/Filters/Core -IIO/Core -I…/IO/Core -I…/ThirdParty/doubleconversion/vtkdoubleconversion -IThirdParty/doubleconversion/vtkdoubleconversion -IThirdParty/doubleconversion -I…/ThirdParty/doubleconversion -I…/ThirdParty/lz4/vtklz4/lib -IThirdParty/lz4/vtklz4 -IThirdParty/lz4 -I…/ThirdParty/lz4 -IThirdParty/lzma -I…/ThirdParty/lzma -IThirdParty/zlib -I…/ThirdParty/zlib -IIO/Image -I…/IO/Image -IUtilities/DICOMParser -I…/Utilities/DICOMParser -IUtilities/MetaIO/vtkmetaio -IUtilities/MetaIO -I…/Utilities/MetaIO -IThirdParty/jpeg/vtkjpeg -IThirdParty/jpeg -I…/ThirdParty/jpeg -IThirdParty/png -I…/ThirdParty/png -IThirdParty/tiff/vtktiff/libtiff -IThirdParty/tiff -I…/ThirdParty/tiff -IIO/XML -I…/IO/XML -IIO/XMLParser -I…/IO/XMLParser -IThirdParty/expat -I…/ThirdParty/expat -IImaging/Core -I…/Imaging/Core -IRendering/Context2D -I…/Rendering/Context2D -IFilters/General -I…/Filters/General -ICommon/ComputationalGeometry -I…/Common/ComputationalGeometry -IRendering/Core -I…/Rendering/Core -ICommon/Color -I…/Common/Color -IFilters/Sources -I…/Filters/Sources -IRendering/FreeType -I…/Rendering/FreeType -IThirdParty/freetype -I…/ThirdParty/freetype -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -mfpu=neon -Wa,–noexecstack -Wformat -Werror=format-security -stdlib=libc++ -O0 -fno-limit-debug-info -fPIC -std=c++11 -MD -MT IO/Export/CMakeFiles/vtkIOExport.dir/vtkGL2PSExporter.cxx.o -MF IO\Export\CMakeFiles\vtkIOExport.dir\vtkGL2PSExporter.cxx.o.d -o IO/Export/CMakeFiles/vtkIOExport.dir/vtkGL2PSExporter.cxx.o -c …/IO/Export/vtkGL2PSExporter.cxx  
…/IO/Export/vtkGL2PSExporter.cxx:22:10: fatal error: ‘vtk\_gl2ps.h’ file not found  
#include “vtk\_gl2ps.h”  
^ ~~~~~~~~~~~~  
1 error generated.  
[15/1033] Building CXX object IO/Export/CMakeFiles/vtkIOExport.dir/vtkPOVExporter.cxx.o  
ninja: build stopped: subcommand failed.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [May 10, 2019, 7:59am UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/2 "2019-05-10T07:59:09Z")

</div>

Please include more info on what you are trying to do and what is not working.

---

<div class="post-metadata">

### Author: ![ruanwenfeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ruanwenfeng/32/394_2.png) [@ruanwenfeng](https://discourse.vtk.org/u/ruanwenfeng)
#### Post date: [May 10, 2019, 8:11am UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/4 "2019-05-10T08:11:42Z")

</div>

use ndk tool chain

---

<div class="post-metadata">

### Author: ![ruanwenfeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ruanwenfeng/32/394_2.png) [@ruanwenfeng](https://discourse.vtk.org/u/ruanwenfeng)
#### Post date: [May 10, 2019, 8:12am UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/5 "2019-05-10T08:12:13Z")

</div>

I want to use VTK on Android.  
Some problems have been solved, but there are still some problems that can not be solved.

Here is one of the problems

```
…/IO/Export/vtkGL2PSExporter.cxx:22:10: fatal error: ‘vtk_gl2ps.h’ file not found
#include “vtk_gl2ps.h”
^ ~~~~~~~~~~~~
1 error generated.
[15/1033] Building CXX object IO/Export/CMakeFiles/vtkIOExport.dir/vtkPOVExporter.cxx.o
ninja: build stopped: subcommand failed
```

---

<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: [May 10, 2019, 12:07pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/6 "2019-05-10T12:07:20Z")

</div>

There’s the `VTK_ANDROID_BUILD` option which should do things properly. It makes a superbuild which generates the VTK executables for the host and then uses those with the Android toolchain to compile for the device.

---

<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: [May 10, 2019, 12:09pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/7 "2019-05-10T12:09:50Z")

</div>

Cc: @ken-martin

---

<div class="post-metadata">

### Author: ![ruanwenfeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ruanwenfeng/32/394_2.png) [@ruanwenfeng](https://discourse.vtk.org/u/ruanwenfeng)
#### Post date: [May 10, 2019, 1:03pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/8 "2019-05-10T13:03:44Z")

</div>

I use the same method

---

<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: [May 10, 2019, 1:08pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/9 "2019-05-10T13:08:53Z")

</div>

This seems to be with 8.2. On `master`, this class is masked to not build on Android. Try commenting out the `vtkGL2PSExporter` source addition in the associated `CMakeLists.txt`.

---

<div class="post-metadata">

### Author: ![ruanwenfeng](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ruanwenfeng/32/394_2.png) [@ruanwenfeng](https://discourse.vtk.org/u/ruanwenfeng)
#### Post date: [May 10, 2019, 1:14pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/10 "2019-05-10T13:14:05Z")

</div>

Thank for your reply  
The following problem has occurred. I am going to collapse

```
D:\Android\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi28 --gcc-toolchain=D:/Android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DGLEW_STATIC -DVTK_IN_VTK -IRendering/ContextOpenGL2 -I../Rendering/ContextOpenGL2 -ICommon/Core -I../Common/Core -IUtilities/KWIML -I../Utilities/KWIML -IUtilities/KWSys -I../Utilities/KWSys -IThirdParty/utf8 -I../ThirdParty/utf8 -ICommon/DataModel -I../Common/DataModel -ICommon/Math -I../Common/Math -ICommon/Misc -I../Common/Misc -ICommon/System -I../Common/System -ICommon/Transforms -I../Common/Transforms -IImaging/Core -I../Imaging/Core -ICommon/ExecutionModel -I../Common/ExecutionModel -IRendering/Context2D -I../Rendering/Context2D -IFilters/General -I../Filters/General -ICommon/ComputationalGeometry -I../Common/ComputationalGeometry -IFilters/Core -I../Filters/Core -IRendering/Core -I../Rendering/Core -ICommon/Color -I../Common/Color -IFilters/Geometry -I../Filters/Geometry -IFilters/Sources -I../Filters/Sources -IRendering/FreeType -I../Rendering/FreeType -IThirdParty/freetype -I../ThirdParty/freetype -IThirdParty/zlib -I../ThirdParty/zlib -IRendering/OpenGL2 -I../Rendering/OpenGL2 -IThirdParty/glew -I../ThirdParty/glew -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -O0 -fno-limit-debug-info -fPIC -std=c++11 -MD -MT Rendering/ContextOpenGL2/CMakeFiles/vtkRenderingContextOpenGL2.dir/vtkOpenGLContextDevice2D.cxx.o -MF Rendering\ContextOpenGL2\CMakeFiles\vtkRenderingContextOpenGL2.dir\vtkOpenGLContextDevice2D.cxx.o.d -o Rendering/ContextOpenGL2/CMakeFiles/vtkRenderingContextOpenGL2.dir/vtkOpenGLContextDevice2D.cxx.o -c ../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx
In file included from ../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:60:
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2DPrivate.h:316:32: error: use of undeclared identifier 'GL_DRAW_BUFFER'
      ostate->vtkglGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
                               ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:342:14: error: use of undeclared identifier 'GL_LINE_SMOOTH'
    glEnable(GL_LINE_SMOOTH);
             ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:369:15: error: use of undeclared identifier 'GL_LINE_SMOOTH'
    glDisable(GL_LINE_SMOOTH);
              ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1174:16: error: use of undeclared identifier 'GL_POINT_SPRITE'
      glEnable(GL_POINT_SPRITE);
               ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1175:17: error: use of undeclared identifier 'GL_POINT_SPRITE'
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
                ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1175:34: error: use of undeclared identifier 'GL_COORD_REPLACE'
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
                                 ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1177:23: error: use of undeclared identifier 'GL_POINT_SPRITE_COORD_ORIGIN'
    glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
                      ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1177:53: error: use of undeclared identifier 'GL_LOWER_LEFT'
    glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
                                                    ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1185:17: error: use of undeclared identifier 'GL_POINT_SPRITE'
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
                ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1185:34: error: use of undeclared identifier 'GL_COORD_REPLACE'
      glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
                                 ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1186:17: error: use of undeclared identifier 'GL_POINT_SPRITE'
      glDisable(GL_POINT_SPRITE);
                ^
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:2001:3: error: use of undeclared identifier 'glPointSize'; did you mean 'SetPointSize'?
  glPointSize(size);
  ^ ~~~~~~~~~~
  SetPointSize
../Rendering/ContextOpenGL2/vtkOpenGLContextDevice2D.cxx:1994:32: note: 'SetPointSize' declared here
void vtkOpenGLContextDevice2D::SetPointSize(float size)
                               ^
12 errors generated.
ninja: build stopped: subcommand failed.
```

---

<div class="post-metadata">

### Author: ![Sohrab\_Azami](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sohrab_azami/32/1210_2.png) [@Sohrab\_Azami](https://discourse.vtk.org/u/Sohrab_Azami)
#### Post date: [February 9, 2022, 4:27pm UTC](https://discourse.vtk.org/t/i-want-to-use-vtk-on-android/945/11 "2022-02-09T16:27:54Z")

</div>

@ben.boeckel  
I like to use vtk 9.1.x in android studio as a native c++ android library module.

1. I built vtk for android many times as static and dynamic in wsl2 linux under windows 10.

2. command in Ubuntu terminal under wsl2 linux subsystem of windows 10:  
Android/Sdk/cmake/3.18.1/bin/cmake.exe -DVTK\_ANDROID\_BUILD=ON -DANDROID\_ARCH\_ABI=arm64-v8a -DANDROID\_NATIVE\_API\_LEVEL=26 -DANDROID\_NDK=/home/myname/Android/Sdk/ndk/21.4.xxx -DANDROID -DCMAKE\_MAKE\_PROGRAM=/home/myname/Android/Sdk/cmake/3.18.1/bin/ninja -DCMAKE\_SYSTEM\_NAME=Android -DCMAKE\_SYSTEM\_VERSION=26 -DANDROID\_PLATFORM=Android-26 -DANDROID\_TOOLCHAIN=/home/myname/Android/Sdk/ndk/21.4.xxx/toolchains/llvm/prebuilt/linux-x86\_64/ -DCMAKE\_C\_COMPILER=/usr/bin/clang -DCMAKE\_CXX\_COMPILER=/usr/bin/clang++ -DCMAKE\_CXX\_STANDARD=11 -DBUILD\_SHARED\_LIBS=0 -GNinja …/…/

3. glang & clang++ seems to be the only toolchain used after ndk r17c! that is why I use clang. it seems goes out to my ndk toolchains and calls the aarch64-linux-android26-clang/clang++ hopefully. llvm is the backend for clang toolchain.

4. I also to ccmake to check the setting of the cmake and configure in the ccmake GUI so that it picks up clang toolchain components like clang++ clang clang-ar(archiver for static build) clang-nm etc.  
then I do final configure and generate the code.

5. I do /home/myname/Android/Sdk/cmake/3.18.1/bin/ninja.  
vtk build as static library with all .a library extension under CMakeEternals/…

6. I have all my include files and libraries in include/ and lib/ directories in inside the arm64-v8a folder! I check the .a library files with 7zip open archive and it seems different xx.o objects are inside the vtkxxxx.a library, here I assume It is a fine build

7. I copy include/ and lib/ folders of vtk to the windows 10 android studio project folder.

8. I create an android basic project, or it could be native c++ application project.

9. under this android project I add a android library module called vtk. under /src/main/ folder I create a folder called jni; in that I add my android build vtk arm64-v8a lib/ & include/ folders; I add a CMakeLists.txt file; I add vtk-lib.cpp file to include my vtk cone example in that, all include files for cone is there.

10. in the CMakeLists.txt I basically add all my vtkxx.a libraries from android linux built in that. in the target\_link\_libraries(-Wl, --start-group -L ${TARGET\_OUT} … -Wl, --end-group), this assures me that all dependencies are considered inside the vtkxxx.a libraries.

11. I configure my android vtk library to use externalNativeBuild{cmake{ cppflags … arguments… abiFilters ‘arm64-v8a’}}; I compile the lib-vtk.cpp application properly, because if I have a compile error I see the android studio gives me compile error or the name of vtkxxx.a has typo error and etc. so I am sure it comiles; when it comes to link with ninja it gives me clang++ linker error; when I check it, there is not much in error message except except it is ninja build which fails!  
c/c++ clang++: error: linker command failed with exit code 1use -v to use invocation).

now I wonder how I can check if there is a problem with my android build of VTK in wsl linux ubuntu? how to check if that is build correctly.  
the ndk version is the same in linux android build For VTK and in android studio I set vtk android library use the same ndk.  
I use the same cmake from ndk 21.4.xxxx toolchain like I explained.

I need to make sure my vtk android build is correct

thanks  
@Sohrab_Azami
