Fix Android API gating: use weak symbols instead of __ANDROID_API__#229
Merged
Conversation
The previous API-28 fix (c6bb70d) was a no-op on the current dockcross-android-arm64 image and the Android build still failed compiling mtmd-helper.cpp (vendor/sheredom/subprocess.h -> posix_spawn*). Root cause: that image is NOT the Google NDK CMake toolchain but a Debian-style cross-clang (/usr/aarch64-linux-android/bin/clang). It never sets ANDROID/ANDROID_ABI, so the if(ANDROID_ABI)-guarded add_compile_definitions(__ANDROID_API__=28) never ran; and it ignores -DANDROID_PLATFORM=android-28 (CMake flags it as an unused variable). bionic gates posix_spawn behind __BIONIC_AVAILABILITY_GUARD(28), which tests __ANDROID_MIN_SDK_VERSION__ (predefined by clang from the target triple) — not __ANDROID_API__ — so even applying that define would not have helped. Fix: define __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__ for the Android build. That forces __BIONIC_AVAILABILITY_GUARD(api) to 1 for every level (declarations always visible) and weak-links symbols newer than the baked-in min-SDK, which resolve at load time on the API-28+ devices the artifact targets. It is never compiler-predefined, so defining it is clean (no -Wmacro-redefined). It also subsumes the getifaddrs (API 24) case. Detection no longer relies on ANDROID_ABI: it uses OS_NAME MATCHES "Android" (CI passes -DOS_NAME=Linux-Android) and the compiler path, plus ANDROID/ANDROID_ABI for a future NDK switch. Also drop the inert -DANDROID_PLATFORM=android-28 from both Android jobs (it only produced an unused-variable warning) and rewrite the CLAUDE.md Android section to document the real mechanism. https://claude.ai/code/session_013jKzHGzz97hiY6t7mp3MGr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__ANDROID_API__=28approach with__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__to properly gate Android bionic declarations on the dockcross cross-compiler toolchain-DANDROID_PLATFORM=android-28from CI build commands, as it is ignored by the Debian-style cross-clang used by dockcrossMotivation
The dockcross-android-arm64 image used by CI is not the Google NDK CMake toolchain—it's a Debian-style cross-clang (
/usr/aarch64-linux-android/bin/clang) that:ANDROID/ANDROID_ABICMake variables-DANDROID_PLATFORM(CMake reports it as unused)__ANDROID_API__from its baked-in target tripleThe old approach of bumping
__ANDROID_API__=28doesn't work on this toolchain because it clashes with the compiler's builtin definition and doesn't move__ANDROID_MIN_SDK_VERSION__, which is what bionic's__BIONIC_AVAILABILITY_GUARD(api)actually tests.The working fix is
__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__, which forces all guarded declarations to be visible and makes newer-API symbols weak references resolved at load time—present on every API-28+ device we target.Changes
CMakeLists.txt:
if(ANDROID_ABI)+add_compile_definitions(__ANDROID_API__=28)with a more robust detection that checksANDROID,ANDROID_ABI,OS_NAME MATCHES "Android", or compiler path__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__instead of__ANDROID_API__.github/workflows/publish.yml:
-DANDROID_PLATFORM=android-28from bothcrosscompile-android-aarch64andcrosscompile-android-aarch64-opencljob stepsCLAUDE.md:
-DANDROID_PLATFORMin CI-DANDROID_PLATFORM=android-28Test plan
Checklist
CONTRIBUTING.mdandCODE_OF_CONDUCT.mdhttps://claude.ai/code/session_013jKzHGzz97hiY6t7mp3MGr