Repository navigation
Android source builds fail after the Hermes source directory changes #59513
Description
Description
An Android source build fails in configureBuildForHermes when its existing CMake build directory points to a previous Hermes source location. CMake exits with "does not match the source ... used to generate cache" before compilation starts.
The original failure came from a pnpm monorepo using pnpm 12.3.4. ccache 4.14.2 was enabled for native compilation. The React Native package path had changed. I have not determined how the old cache survived that change.
The reproducer below uses an upstream checkout. It configures Hermes once, copies the unchanged source tree to another directory, then sets REACT_NATIVE_OVERRIDE_HERMES_DIR to that copy while keeping the existing build directory. The first configure call passes and the second fails. The configure task should recreate the incompatible cache when Gradle runs it again.
The original build used React Native 0.88.0. I also reproduced the source-path mismatch on upstream main at b53ee7f855f879f3eb5063103f83981468578099.
Steps to reproduce
- Clone the reproducer branch and install the upstream dependencies:
git clone --depth 1 --branch codex/reproduce-hermes-cmake-cache-relocation https://github.com/shamilovtim/react-native.git
cd react-native
yarn install --non-interactive --frozen-lockfile-
Set
JAVA_HOMEto JDK 17 andANDROID_HOMEto an Android SDK installation. -
Run the reproducer:
bash repro-hermes-cache-relocation.shThe script runs :packages:react-native:ReactAndroid:hermes-engine:configureBuildForHermes with source builds enabled. The first call succeeds. After the source copy, the second call fails with a CMake source-path mismatch.
With the fix applied, both calls succeed and the third call reports UP-TO-DATE. The script leaves the copied sources in the temporary directory printed in its output.
React Native Version
0.88.0
Affected Platforms
Build - MacOS
Output of npx @react-native-community/cli info
Relevant CLI output from the upstream checkout, with local paths omitted:
System:
OS: macOS 27.0.1
CPU: arm64 Apple M5 Max
Binaries:
Node: 24.22.0
Yarn: 1.22.22
npm: 11.19.1
Languages:
Java: 17.0.20
Additional build details:
Original workspace: pnpm monorepo
pnpm: 12.3.4
ccache: 4.14.2, enabled for the original native build
Gradle: 9.4.1
CMake: 3.30.5
NDK used for upstream validation: 28.2.13676358
React Native in the original build: 0.88.0
Upstream reproduction: main at b53ee7f855f879f3eb5063103f83981468578099
Stacktrace or Logs
Local source paths shortened:
> Task :packages:react-native:ReactAndroid:hermes-engine:configureBuildForHermes FAILED
CMake Error: The source "/tmp/hermes-source-moved/CMakeLists.txt" does not match the source "/tmp/react-native/packages/react-native/sdks/hermes/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
Execution failed for task ':packages:react-native:ReactAndroid:hermes-engine:configureBuildForHermes'.
> Process 'command cmake' finished with non-zero exit value 1
MANDATORY Reproducer
https://github.com/shamilovtim/react-native/tree/codex/reproduce-hermes-cmake-cache-relocation
Screenshots and Videos
No response
Activity