Edit this page

NA-MIC Project Weeks

Back to Projects List

Compile ITK for Android ARM64

Key Investigators

Project Description

To investigate if and how ITK (later VTK, and sometime, maybe, in the distant future, Slicer) can be compiled an run on a mobile phone. Especially interesting is Samung’s DeX mode, with a desktop like experience.

Objective

  1. Objective A. Set up a build environment
  2. Objective B. See if and how ITK can be built
  3. Objective C. Hopefully test it too

Approach and Plan

  1. Review Android tools, cross-compilation options
  2. Set up the environment

Progress and Next Steps

  1. Environment setup done
  2. Compilation done, at 100%! :)

After setting up the software and the environment variables, the build was done on a freshly installed Debian 12. Only cmake was installed from a repo-

Several problems were encountered:

There was another problem: On Android, far is sometimes defined as a macro (especially in <sys/types.h> or ) for compatibility with legacy 16-bit platforms. This means that the compiler throws errors in:

/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5022:20: error: expected identifier or '('
 5022 |         float *far = (float *)dataptr ; size_t jj,nj ;
      |                    ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5025:34: error: expected expression
 5025 |            if( !IS_GOOD_FLOAT(far[jj]) ){
      |                                  ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5026:18: error: expected expression
 5026 |               far[jj] = 0 ;
      |                  ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5034:21: error: expected identifier or '('
 5034 |         double *far = (double *)dataptr ; size_t jj,nj ;
      |                     ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5037:34: error: expected expression
 5037 |            if( !IS_GOOD_FLOAT(far[jj]) ){
      |                                  ^
/home/attila/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib/nifti1_io.c:5038:18: error: expected expression
 5038 |               far[jj] = 0 ;
      |                  ^

This could be overcome by forcing CMake to override the far macro by adding this flag to the configure line:

	-DCMAKE_C_FLAGS="-Dfar=far_nifti" \

So the final configure line was this:

cmake  -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/28.0.12916984/build/cmake/android.toolchain.cmake \
	-S /home/attila/ITK \
	-B /home/attila/ITK/itk-build \
	-DANDROID_ABI=arm64-v8a \
	-DANDROID_PLATFORM=android-21 \
	-DCMAKE_BUILD_TYPE=Release \
	-DBUILD_SHARED_LIBS=ON \
	-DITK_BUILD_DEFAULT_MODULES=ON \
	-DITK_WRAP_PYTHON=OFF \
	-DCMAKE_CROSSCOMPILING_EMULATOR="" \
	-DHAVE_CLOCK_GETTIME_RUN=1 \
	-DITK_USE_SYSTEM_ZLIB=ON \
	-D_libcxx_run_result=0 \
	-D_libcxx_run_result__TRYRUN_OUTPUT="" \
	-DGDCM_USE_SYSTEM_ICONV=ON \
	-DCMAKE_C_FLAGS:STRING="-I/home/attila/libiconv-1.18/android-build/include -Dfar=far_nifti" \
	-DCMAKE_CXX_FLAGS:STRING="-Dfar=far_nifti" \
	-DCMAKE_EXE_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so" \
	-DCMAKE_SHARED_LINKER_FLAGS="-L/home/attila/libiconv-1.18/android-build/lib /home/attila/libiconv-1.18/android-build/lib/libiconv.so"
	-DGDCM_ICONV_INCLUDE_DIR=/home/attila/libiconv-1.18/android-build/include

A few shortcomings:

Illustrations

Screenshot of a 100% build

Background and References

This project relies on the [“Builds of Slicer for ARM-based systems Mac and Linux”] project (https://projectweek.na-mic.org/PW42_2025_GranCanaria/Projects/BuildsOfSlicerForArmBasedSystemsMacAndLinux/)