Error Building VTK for Android

I am currently trying to build vtk for android using these commands:

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

The build is with the vtk version from the master branch, and android-ndk-r21e. The build runs smoothly up to 81%, then fails with the error below:

[ 81%] Performing configure step for 'vtk-android'
-- Android: Targeting API '27' with architecture 'arm', ABI 'armeabi', and processor 'armv5te'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 9.0.9
-- The CXX compiler identification is Clang 9.0.9
-- Check for working C compiler: /home/cmengich/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /home/cmengich/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/cmengich/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/cmengich/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could not use git to determine source version, using version
-- Setting build type to 'Debug' as none was specified.
CMake Error at CMake/vtkCrossCompiling.cmake:7 (find_package):
  Could not find a configuration file for package "VTKCompileTools" that is
  compatible with requested version "".

  The following configuration files were considered but not accepted:

    /home/cmengich/Software/vtk-android-build/CompileTools/vtkcompiletools-config.cmake, version: 9.1.20211011 (64bit)

Call Stack (most recent call first):
  CMakeLists.txt:57 (include)


-- Configuring incomplete, errors occurred!
See also "/home/cmengich/Software/vtk-android-build/CMakeExternals/Build/vtk-android-27-armeabi/CMakeFiles/CMakeOutput.log".
make[2]: *** [CMakeFiles/vtk-android.dir/build.make:108: CMakeExternals/Prefix/vtk-android-27-armeabi/src/vtk-android-stamp/vtk-android-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/vtk-android.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Any suggestions as to how to get passed this error?
Or any suggestions on the best way to build vtk for android that works?

Hrm. It’d be nice if there were more information about why the VTKCompileTools package is not suitable. Does adding --debug-find to the CMAKE_ARGS in CMake/vtkAndroid.cmake for the vtk-android project give any more information?

Hi @ben.boeckel

Adding --debug-find to the CMAKE_ARGS in CMake/vtkAndroid.cmake produces the exact same error, no more information.

Following a search, I found a similar issue here: https://gitlab.kitware.com/vtk/vtk/-/issues/17705, that produces the same error.

Any ideas?

Oh. It seems that CMake is upset that it found 64bit binaries for a 32bit build. It doesn’t know that these are host tools and the arch doesn’t need to match. The issue reported that adding -m32 to the flags for the compiletools build seemed to work.

This is related to this thread:

https://discourse.cmake.org/t/how-to-use-host-tools-using-find-package-when-cross-compiling-eg-qt5linguisttools/4224/3

Hi @ben.boeckel

Thanks for taking the time to help me out.

After installing the necessary libraries, I run the following:

cmake -S vtk-master -B vtk-android-build -DVTK_ANDROID_BUILD=ON -DCMAKE_CXX_FLAGS=-m32
cmake --build vtk-android-build

and still getting the same error.

CMake Error at CMake/vtkCrossCompiling.cmake:7 (find_package):
  Could not find a configuration file for package "VTKCompileTools" that is
  compatible with requested version "".

  The following configuration files were considered but not accepted:

    /home/cmengich/Software/vtk-android-build/CompileTools/vtkcompiletools-config.cmake, version: 9.1.20211011 (64bit)

What am I missing?

Hi @ben.boeckel
I made some progress, and have gotten passed the error raised above.
However, now the build gets to the point below and raises another error:

[  2%] Detecting builtin compiler preprocessor defines for VTKCompileTools
clang++: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang++: warning: argument unused during compilation: '-mthumb' [-Wunused-command-line-argument]
clang++: warning: argument unused during compilation: '-mfpu=vfpv3-d16' [-Wunused-command-line-argument]clang++: warning: argument unused during compilation: '-mfloat-abi=softfp' [-Wunused-command-line-argument]
error: unknown target CPU 'armv7-a'
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64

Any ideas on how to get passed this?

Sorry, no. @ken-martin have you done Android compilation recently?

FYI @Michael

Hi @ben.boeckel, the problem seems to be with the vtk master version.

I successfully built with vtk-8.2.0, with

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

All vtk-9 versions also raised errors when building.

Experienced the same with building for ios, built successfully with vtk-8.2.0.

I did have a follow-up question. How would one go about building for android/ios and include the wrap for python options?