# Android NDK newer than r18 fails to compile

**URL:** https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310
**Category:** Development
**Created:** [July 9, 2019, 11:14am UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310 "2019-07-09T11:14:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hcwiley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hcwiley/32/638_2.png) [@hcwiley](https://discourse.vtk.org/u/hcwiley)
#### Post date: [July 9, 2019, 11:14am UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310/1 "2019-07-09T11:14:41Z")

</div>

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](https://github.com/android-ndk/ndk/wiki/Changelog-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**
```

---

<div class="post-metadata">

### Author: ![hcwiley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hcwiley/32/638_2.png) [@hcwiley](https://discourse.vtk.org/u/hcwiley)
#### Post date: [July 9, 2019, 11:34am UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310/2 "2019-07-09T11:34:43Z")

</div>

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

---

<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: [July 9, 2019, 2:08pm UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310/3 "2019-07-09T14:08:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.vtk.org/user_avatar/discourse.vtk.org/brad.king/32/34_2.png) [@brad.king](https://discourse.vtk.org/u/brad.king)
#### Post date: [July 9, 2019, 2:23pm UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310/4 "2019-07-09T14:23:36Z")

</div>

CMake does not support NDK r19 or higher. See [CMake Issue 18739](https://gitlab.kitware.com/cmake/cmake/issues/18739).

---

<div class="post-metadata">

### Author: ![hcwiley](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hcwiley/32/638_2.png) [@hcwiley](https://discourse.vtk.org/u/hcwiley)
#### Post date: [July 10, 2019, 5:52am UTC](https://discourse.vtk.org/t/android-ndk-newer-than-r18-fails-to-compile/1310/5 "2019-07-10T05:52:42Z")

</div>

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

Side note, really glad I found this discourse 😅
