Skip to content

New Android NDK support request #21345

@holmesconan

Description

@holmesconan

Referenced from NDK Revision History, since Android NDK r11 (March 2016), clang is the strongly recommended compiler and toolchain. And the GCC deprecation warning shown from Android NDK r13b (October 2016). Then since Android NDK r18b (September 2018), GCC is removed from the toolchan and only clang is supported.

When do cross-compile with the latest Android NDK r23 for any autotools based library like libiconv, errors will raise as:

...
-- Configuring x86-android-dbg
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:127 (message):
    Command failed: /usr/bin/bash -c "V=1 ./../src/1.16-b0c41d3469.clean/configure  \"--enable-extra-encodings\" \"--without-libiconv-prefix\" \"--without-libintl-prefix\" \"--disable-silent-rules\" \"--verbose\" \"--disable-shared\" \"--enable-static\" \"--prefix=/home/vcpkg/installed/x86-android/debug\" \"--bindir=\\${prefix}/../tools/libiconv/debug/bin\" \"--sbindir=\\${prefix}/../tools/libiconv/debug/sbin\" \"--libdir=\\${prefix}/lib\" \"--includedir=\\${prefix}/../include\" \"--datarootdir=\\${prefix}/share/libiconv\""
    Working Directory: /home/vcpkg/buildtrees/libiconv/x86-android-dbg
    Error code: 77
    See logs for more information:
      /home/vcpkg/buildtrees/libiconv/config-x86-android-dbg-out.log
      /home/vcpkg/buildtrees/libiconv/config-x86-android-dbg-err.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_configure_make.cmake:796 (vcpkg_execute_required_process)
  ports/libiconv/portfile.cmake:29 (vcpkg_configure_make)
  scripts/ports.cmake:142 (include)


Error: Building package libiconv:x86-android failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `git pull` and `./vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
  package: libiconv[core]:x86-android -> 1.16#11
  vcpkg version: 2021-11-02-af04ebf6274fd6f7a941bff4662b3955c64f6f42
  vcpkg-tool version: 897ff9372 2021-11-11 (9 hours ago)

Additionally, attach any relevant sections from the log files above.

And config-x86-android-dbg-err.log shown

configure: error: in `/home/vcpkg/buildtrees/libiconv/x86-android-dbg':
configure: error: C compiler cannot create executables
See `config.log' for more details

And config-x86-android-dbg-out.log shown

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make sets $(MAKE)... (cached) yes
checking for gcc... gcc
checking whether the C compiler works... no

Obviously, the configure script did not find the right compiler for cross-compile.

Proposed solution
issue #20844 and draft PR #21222 proposed a temporary solution that forces provides CC and CXX (and other tools like strip, ar, ranlib, etc). But it just solved libraries that used autotools build system.

other minor fixes for CMake build system. Such as bzip2:x86-android.

$ cat buildtrees/bzip2/config-x86-android-dbg-out.log
-- ANDROID_PLATFORM not set. Defaulting to minimum supported version 16.
-- Android: Targeting API '16' with architecture 'x86', ABI 'x86', and processor 'i686'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 12.0.8
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/AndroidSdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vcpkg/buildtrees/bzip2/x86-android-dbg

even though the library is build without error.

$ head -n 10 scripts/toolchains/android.cmake
set(ANDROID_CPP_FEATURES "rtti exceptions" CACHE STRING "")
set(CMAKE_SYSTEM_NAME Android CACHE STRING "")
set(ANDROID_TOOLCHAIN clang CACHE STRING "")
set(ANDROID_NATIVE_API_LEVEL ${CMAKE_SYSTEM_VERSION} CACHE STRING "")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang CACHE STRING "")

According to the reference, ANDROID_NATIVE_API_LEVEL is the alias of ANDROID_PLATFORM, but one needs to specify both instead of one.

Describe alternatives you've considered
There are many other build systems that vcpkg supported. And CMake is the primary build system now (instead of ndk-build). And there is a CMake toolchain file that prepared the build environment. So after the temporary solution, we need to reconsider the whole picture for the Android triplet.

As the reviewer of #21222 @Neumann-A said:

Again I feel like the default android toolchain vcpkg provides should be removed and replaced with specialized toolchains for each architecture and case. There seems to be a bigger misunderstanding of vcpkg is supposed to work and what work should be done by the configure scripts.

And we need more consideration of how to pass

  1. ANDROID_ABI
  2. ANDROID_PLATFORM
  3. ANDROID_API_LEVEL
  4. etc

to most build systems. More discussion please read the review comment of #21222 .

Metadata

Metadata

Assignees

Labels

Stalecategory:community-tripletA PR or issue related to community triplets not officially validated by the vcpkg team.category:tool-updateThe issue is with build tool or build script, which requires update or should be executed correctly

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions