Skip to content

fix(cmake-rn): let ANDROID_STL be overridden via --define - #433

Merged
kraenhansen merged 1 commit into
nextfrom
claude/issue-418-android-stl
Aug 13, 2026
Merged

fix(cmake-rn): let ANDROID_STL be overridden via --define#433
kraenhansen merged 1 commit into
nextfrom
claude/issue-418-android-stl

Conversation

@kraenhansen

Copy link
Copy Markdown
Collaborator

Addresses the Android half of #418 ("Make the hardcoded ANDROID_STL build setting configurable"). The Apple half (CODE_SIGNING_ALLOWED) is a separate PR.

What was wrong

ANDROID_STL was hardcoded to c++_shared in packages/cmake-rn/src/platforms/android.ts, with a // TODO: Make this configurable comment and no way for a consumer to override it — a problem for an addon that's genuinely self-contained (wants c++_static) or, more importantly, one that must match a prebuilt third-party dependency's STL.

Findings re: #227

cmake-rn already has a generic -D/--define option (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 covers ANDROID_STL for free... in principle.

In practice it didn't work for the Android platform's own default variables: commonDefinitions spread the user's define array before the hardcoded object containing ANDROID_STL: "c++_shared". Since CMake resolves a cache variable passed multiple times via -D to 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 --define entries are applied last, after our own defaults (ANDROID_STL included). The default (c++_shared, matching what React Native itself uses) is unchanged; a consumer can now do:

cmake-rn --define ANDROID_STL=c++_static

Extracted the definitions-building logic into an exported, pure buildCommonDefinitions function 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 build
  • pnpm --filter cmake-rn run test
  • pnpm exec eslint packages/cmake-rn/src/platforms/android.ts packages/cmake-rn/src/platforms/android.test.ts
  • pnpm exec prettier --check on touched files
  • Added a minor changeset for cmake-rn (new capability, backward compatible — default unchanged)

🤖 Generated with Claude Code

https://claude.ai/code/session_01DaK9eAAF5G8wj6UT8VekAm


Generated by Claude Code

@kraenhansen kraenhansen added the CMake RN Our `cmake` wrapping CLI label Aug 13, 2026
@kraenhansen kraenhansen self-assigned this Aug 13, 2026
@kraenhansen kraenhansen added the Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) label Aug 13, 2026 — with Claude
`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
kraenhansen force-pushed the claude/issue-418-android-stl branch from 904c820 to 1ad025c Compare August 13, 2026 10:26
@kraenhansen
kraenhansen merged commit 0c1d597 into next Aug 13, 2026
16 checks passed
@kraenhansen
kraenhansen deleted the claude/issue-418-android-stl branch August 13, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) CMake RN Our `cmake` wrapping CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants