Skip to content

Fix mixed target_link_libraries signature for common_flags in ReactNative-application.cmake - #60307

Open
JagguDada01 wants to merge 1 commit into
react:mainfrom
JagguDada01:fix/cmake-common-flags-keyword-linking
Open

JagguDada01 wants to merge 1 commit into
react:mainfrom
JagguDada01:fix/cmake-common-flags-keyword-linking

Conversation

@JagguDada01

Copy link
Copy Markdown

Summary:

Fixes Android CMake configure failures when an autolinked library or app-level codegen target uses the keyword signature of target_link_libraries (PRIVATE, PUBLIC, or INTERFACE).

Problem

ReactNative-application.cmake links common_flags onto each target in AUTOLINKED_LIBRARIES and APP_CODEGEN_TARGET using the plain target_link_libraries(<target> common_flags) signature. CMake forbids mixing plain and keyword signatures on the same target, so any autolinked library whose own CMakeLists.txt uses PRIVATE, PUBLIC, or INTERFACE fails CMake configure.

Root Cause

Generated codegen targets (e.g. from GenerateModuleJniH.js) use the plain target_link_libraries signature, while third-party native libraries often use PRIVATE/PUBLIC/INTERFACE. Calling either plain target_link_libraries(... common_flags) or keyword target_link_libraries(... PRIVATE common_flags) fails when the target used the opposite signature.

Solution

Add a target_link_common_flags(target) helper in packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake that attaches common_flags via target properties (LINK_LIBRARIES, or INTERFACE_LINK_LIBRARIES for INTERFACE_LIBRARY targets) after resolving aliases and skipping missing/imported targets, and call it for both AUTOLINKED_LIBRARIES and APP_CODEGEN_TARGET. This preserves common_flags propagation (folly_FLAGS and RN_STRICT_API) regardless of which target_link_libraries signature the target used.

Fixes #60000

Changelog:

[ANDROID] [FIXED] - Avoid mixing target_link_libraries signatures when linking common_flags to autolinked and codegen targets in ReactNative-application.cmake

Test Plan:

Verified locally using cmake (v4.4.3) against packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake with mocked ReactAndroid/fbjni package targets across three scenarios:

  1. RN_STRICT_API=OFF configure & build with:
    • SHARED autolinked library using target_link_libraries(... PRIVATE ...)
    • STATIC autolinked library using target_link_libraries(... PUBLIC ...)
    • OBJECT autolinked library using plain target_link_libraries(...)
    • INTERFACE library, ALIAS target, IMPORTED target, and non-existent target
    • App-level codegen target (APP_CODEGEN_TARGET) using PRIVATE
      Verified every compiled translation unit received folly_FLAGS (FOLLY_USE_LIBCPP) and linked cleanly into appmodules.
  2. RN_STRICT_API=ON configure & build verifying RN_STRICT_API is defined on all targets alongside folly_FLAGS.
  3. Empty APP_CODEGEN_TARGET directory configure & build.

(Full Android Gradle/NDK rn-tester build was not run locally because Android NDK/node_modules are not installed in this environment; CI Android checks will cover the full NDK build.)

@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Hi @JagguDada01!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@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 Nov 26, 2026
@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Nov 26, 2026

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

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

Projects

None yet

1 participant