Skip to content

Use the library build directory for Android codegen autolinking - #60548

Open
izbari wants to merge 1 commit into
react:mainfrom
izbari:fix/relocated-codegen-cmake
Open

izbari wants to merge 1 commit into
react:mainfrom
izbari:fix/relocated-codegen-cmake

Conversation

@izbari

@izbari izbari commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Fixes react-native-community/cli#2898. Moving an Android library's Gradle build directory makes Codegen and CMake disagree about where the generated JNI sources live. In the reporter's app, CMake skips react_codegen_rnworklets and the release build fails compiling autolinking.cpp with 'rnworklets.h' file not found.

The Gradle plugin can resolve the generated JNI path from the included library project's layout.buildDirectory. Pass that path to the autolinking task as a lazy task input when the CLI reports the conventional generated CMake path. Libraries with a separate CMake project and pure C++ dependencies continue through their existing paths.

Changelog

[ANDROID] [FIXED] - Fix native autolinking when an Android library generates Codegen sources in a relocated Gradle build directory.

Test Plan

  • In packages/gradle-plugin, ran ./gradlew :react-native-gradle-plugin:test --tests '*autolinking_usesLibraryBuildDirectoryForGeneratedCmake'. Before the fix the assertion showed worklets/build/generated/source/codegen/jni/ in the generated CMake. The test expects build/modules/worklets/generated/source/codegen/jni/ after changing the library's build directory, even when the task has already been realized. The same test passed with the fix. Ran ./gradlew test --max-workers=2 for the Gradle plugin build. All 295 tests passed.
  • On macOS, ran the issue's reproducer with React Native 0.88.1, CLI 22.0.0-alpha.0 and react-native-worklets 0.14.0. The unmodified release build failed on the missing header. Applied the production changes to the app's installed Gradle plugin and reran ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a --max-workers=2 --console=plain in android/. The release APK built successfully. The generated CMake adds the worklets target from android/build/modules/react-native-worklets/generated/source/codegen/jni/.

Codex assisted with the implementation and ran the verification above.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
Signed-off-by: izbari <73957984+izbari@users.noreply.github.com>
@izbari
izbari force-pushed the fix/relocated-codegen-cmake branch from 2e973cd to 215b9dc Compare December 4, 2026 13:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android autolinking skips a library's codegen when its Gradle build directory is moved: the default cmakeListsPath assumes android/build

1 participant