fix(cmake-rn): let ANDROID_STL be overridden via --define - #433
Merged
Conversation
`ANDROID_STL` was hardcoded to `c++_shared` when configuring Android builds, with no escape hatch for an addon that needs `c++_static` or must match a prebuilt third-party dependency's STL (#418). The generic `-D`/`--define` cache-variable pass-through (added for #332, which #227 also asks for) already lets a consumer set arbitrary CMake cache variables, including `ANDROID_STL` - but it didn't actually work: our hardcoded Android defaults were appended to the CMake command line *after* the user-provided `-D` arguments, and CMake resolves a variable set multiple times via `-D` to its last occurrence, so the hardcoded value always won. Fix the ordering so the user's `--define` is applied last. `ANDROID_STL` still defaults to `c++_shared`, matching what React Native itself uses. Extract the CMake definitions building into an exported `buildCommonDefinitions` and add unit tests covering the default and the override precedence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaK9eAAF5G8wj6UT8VekAm
kraenhansen
force-pushed
the
claude/issue-418-android-stl
branch
from
August 13, 2026 10:26
904c820 to
1ad025c
Compare
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.
Addresses the Android half of #418 ("Make the hardcoded
ANDROID_STLbuild setting configurable"). The Apple half (CODE_SIGNING_ALLOWED) is a separate PR.What was wrong
ANDROID_STLwas hardcoded toc++_sharedinpackages/cmake-rn/src/platforms/android.ts, with a// TODO: Make this configurablecomment and no way for a consumer to override it — a problem for an addon that's genuinely self-contained (wantsc++_static) or, more importantly, one that must match a prebuilt third-party dependency's STL.Findings re: #227
cmake-rnalready has a generic-D/--defineoption (added in #332, well before #227 was filed) that passes arbitrary CMake cache variables through to the configure step — exactly the kind of pass-through #227 asks for, and it already coversANDROID_STLfor free... in principle.In practice it didn't work for the Android platform's own default variables:
commonDefinitionsspread the user'sdefinearray before the hardcoded object containingANDROID_STL: "c++_shared". Since CMake resolves a cache variable passed multiple times via-Dto its last occurrence on the command line, our hardcoded default always silently overrode a user's--define ANDROID_STL=....The fix
Reordered so the user's
--defineentries are applied last, after our own defaults (ANDROID_STLincluded). The default (c++_shared, matching what React Native itself uses) is unchanged; a consumer can now do:Extracted the definitions-building logic into an exported, pure
buildCommonDefinitionsfunction so it's independently testable without mocking the NDK/filesystem, and added unit tests covering the default value and the override-precedence fix.Given the existing pass-through option already substantially covers this, no new dedicated
--android-stl-style flag was added — that would just duplicate--define.Validation
pnpm install && pnpm run buildpnpm --filter cmake-rn run testpnpm exec eslint packages/cmake-rn/src/platforms/android.ts packages/cmake-rn/src/platforms/android.test.tspnpm exec prettier --checkon touched filesminorchangeset forcmake-rn(new capability, backward compatible — default unchanged)🤖 Generated with Claude Code
https://claude.ai/code/session_01DaK9eAAF5G8wj6UT8VekAm
Generated by Claude Code