Skip to content

fix(gradle-plugin): guard missing autolinked JNI dirs#56886

Closed
Phecda wants to merge 2 commits into
facebook:mainfrom
Phecda:fix/android-autolinking-missing-jni-dirs
Closed

fix(gradle-plugin): guard missing autolinked JNI dirs#56886
Phecda wants to merge 2 commits into
facebook:mainfrom
Phecda:fix/android-autolinking-missing-jni-dirs

Conversation

@Phecda
Copy link
Copy Markdown
Contributor

@Phecda Phecda commented May 19, 2026

Summary:

Related to #56334.

GenerateAutolinkingNewArchitecturesFileTask currently emits unconditional add_subdirectory(...) calls for autolinked New Architecture JNI/codegen directories.

During clean, Android Studio native model configuration, or other native cleanup/configuration flows, some dependency codegen directories may not exist yet. CMake then fails before clean/configuration can complete:

add_subdirectory given source ".../android/build/generated/source/codegen/jni/"
which is not an existing directory

This changes the generated Android-autolinking.cmake to:

  • initialize AUTOLINKED_LIBRARIES as an empty list;
  • only call add_subdirectory(...) when the native directory exists;
  • append each autolinked target only after its directory has been added.

That keeps existing generated JNI directories linked as before while allowing native clean/model configuration to skip directories that have not been generated yet.

Changelog:

[ANDROID] [FIXED] - Guard missing autolinked JNI directories in generated CMake during native clean/model configuration.

Test Plan:

./gradlew -p packages/gradle-plugin :react-native-gradle-plugin:test --tests com.facebook.react.tasks.GenerateAutolinkingNewArchitecturesFileTaskTest

Result:

BUILD SUCCESSFUL

Scope this change to Android New Architecture CMake autolinking. Generate Android-autolinking.cmake so missing codegen JNI directories are skipped instead of failing clean/native model configuration, and only append libraries after their directories are added.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 19, 2026
@Phecda Phecda marked this pull request as ready for review May 19, 2026 14:08
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label May 19, 2026
Copy link
Copy Markdown
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

if(EXISTS "$nativeFolderPath")
add_subdirectory("$nativeFolderPath" ${libraryName}_autolinked_build)
list(APPEND AUTOLINKED_LIBRARIES $CODEGEN_LIB_PREFIX${libraryName})
endif()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great however I'm a bit concerned of this potentially exposing us to silent failures. Perhaps we should emit a message if the folder is not existing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I added warning messages when an autolinked directory is skipped. Thanks for the review!

@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 20, 2026

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D105826478.

@meta-codesync meta-codesync Bot closed this in 948835d May 20, 2026
@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Phecda in 948835d

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label May 20, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 20, 2026

@cortinico merged this pull request in 948835d.

@Phecda Phecda deleted the fix/android-autolinking-missing-jni-dirs branch May 21, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants