Android NDK newer than r18 fails to compile

Android is currently not building when using the latest NDK r20 or the previous r19. This means we should look at the CHANGELOG for NDK r19 to determine the breaking change. Compiling fails after compile tools:

-- Android: Targeting API '26' with architecture 'arm64', ABI 'arm64-v8a', and processor 'aarch64'
-- Android: Selected Clang toolchain 'aarch64-linux-android-clang' with GCC toolchain ''
-- The C compiler identification is Clang 8.0.2
-- The CXX compiler identification is Clang 8.0.2
-- Check for working C compiler: /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
-- Check for working C compiler: /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang -- broken
CMake Error at /usr/local/Cellar/cmake/3.14.5/share/cmake/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/hcwiley/scandy/git/scandy-core/dependencies/vtk/vtk-android-8.90.0-70fea84/CMakeExternals/Build/vtk-android-26-arm64-v8a/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_1c300/fast 
    /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/cmTC_1c300.dir/build.make CMakeFiles/cmTC_1c300.dir/build
    Building C object CMakeFiles/cmTC_1c300.dir/testCCompiler.c.o
    /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=/usr/local/opt/android-ndk/toolchains//prebuilt/darwin-x86_64 --sysroot=/usr/local/opt/android-ndk/sysroot  -isystem /usr/local/opt/android-ndk/sysroot/usr/include -isystem /usr/local/opt/android-ndk/sysroot/usr/include/aarch64-linux-android  -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=26 -fexceptions  -g -fPIE   -o CMakeFiles/cmTC_1c300.dir/testCCompiler.c.o   -c /Users/hcwiley/scandy/git/scandy-core/dependencies/vtk/vtk-android-8.90.0-70fea84/CMakeExternals/Build/vtk-android-26-arm64-v8a/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_1c300
    /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/cmTC_1c300.dir/link.txt --verbose=1
    /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-none-linux-android --gcc-toolchain=/usr/local/opt/android-ndk/toolchains//prebuilt/darwin-x86_64 --sysroot=/usr/local/opt/android-ndk/platforms/android-26/arch-arm64 -funwind-tables -no-canonical-prefixes -D__ANDROID_API__=26 -fexceptions  -g  -Wl,--gc-sections  CMakeFiles/cmTC_1c300.dir/testCCompiler.c.o  -o cmTC_1c300 
    ld: unknown option: --sysroot=/usr/local/opt/android-ndk/platforms/android-26/arch-arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[4]: *** [cmTC_1c300] Error 1
    make[3]: *** [cmTC_1c300/fast] Error 2
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:14 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/hcwiley/scandy/git/scandy-core/dependencies/vtk/vtk-android-8.90.0-70fea84/CMakeExternals/Build/vtk-android-26-arm64-v8a/CMakeFiles/CMakeOutput.log".
See also "/Users/hcwiley/scandy/git/scandy-core/dependencies/vtk/vtk-android-8.90.0-70fea84/CMakeExternals/Build/vtk-android-26-arm64-v8a/CMakeFiles/CMakeError.log".
make[2]: *** [CMakeExternals/Prefix/vtk-android-26-arm64-v8a/src/vtk-android-stamp/vtk-android-configure] Error 1
make[1]: *** [CMakeFiles/vtk-android.dir/all] Error 2
make: *** [all] Error 2

Some additional logs:

$ /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --version

Android (5058415 based on r339409) clang version 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec746213857d083c0e8b0abb568790) (https://android.googlesource.com/toolchain/llvm 7a6618d69e7e8111e1d49dc9e7813767c5ca756a) (based on LLVM 8.0.2svn)

Target: x86_64-apple-darwin18.6.0

Thread model: posix

InstalledDir: /usr/local/opt/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin

and

$ ls -la /usr/local/opt/android-ndk/platforms/android-26/arch-arm64/

total 0

drwxr-xr-x@ 3 hcwiley staff 96 Feb 28 23:41 **.**

drwxr-xr-x@ 6 hcwiley staff 192 Feb 28 23:41 **..**

drwxr-xr-x@ 3 hcwiley staff 96 Feb 28 23:41 **usr**

@ken-martin per usual… :point_up: Android developments thought you might want to be aware of

This might be more CMake-related than VTK-related. @brad.king?

CMake does not support NDK r19 or higher. See CMake Issue 18739.

That makes sense! Given that opencv 4.1.0 also does not compile with ndk >=19.

Side note, really glad I found this discourse :sweat_smile: