Skip to content

[android] Android NDK r23 and clang support #20844

@holmesconan

Description

@holmesconan

I was trying to embed python into my Android App. So I need to build a bunch of C/C++ libraries besides the libpython3.x.a. Since Android NDK r21, the GCC toolchain is dropped and only clang as the default compiler. I have written some scripts to build some libraries and a little of patches. But in order to finish the project, I need more C/C++ libraries. So I switch to vcpkg. After some tests, I found that most libraries that are built with CMake seem to work well with the *-android triplets contributed by the community, but others that are based on autotools (e.g. configure + make) does not work well. For example, the libiconv failed during the config stage due to it is trying to compile with gcc.

There are several problems:

  1. the VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES contains -static-libc++ which will be convert to -l-static-libc++ since it is not the standard library reference style.
  2. CC and CXX should be set in the environment to help the configure script find the right compiler
  3. AR, RANLIB and STRIP, perhaps READELF should also be set in the environment for library generate.

For python3:*-android, patches should be apply to the setup.py for cross-compiling the standard libraries.

So I have made a draft PR in http://github.com/holmescn/vcpkg on branch fix-android-ndk-r23. But there are some problem that I don't know how to resolve, so I cannot make a PR right now:

  1. There is an option of ANDROID_API which needed to be appended to the cross-compiling compiler like armv7a-linux-androideabi${ANDROID_API}-clang. I don't know where to add it.
  2. The CMAKE_HOST_SYSTEM_VERSION is empty on macOS which is needed in the --build option like --build=x86_64-apple-darwin${CMAKE_HOST_SYSTEM_VERSION}. Though this could be solved by execute_process of uname -r.
  3. The _vcpkg_determine_autotools_host_cpu and _vcpkg_determine_autotools_target_cpu seem not handle Android host and target well. I implement them using MATCHES on VCPKG_DETECTED_CMAKE_SYSTEM_PROCESSOR but it takes more code.

The python patches is another story. I would like to keep track with the problem until the PR is ready to push.

Metadata

Metadata

Labels

category:vcpkg-featureThe issue is a new capability of the tool that doesn’t already exist and we haven’t committed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions