fix(android): don't hardcode default cmakeListsPath for pure c++ modules#2799
Merged
Conversation
…dules this removes the incorrect default `cmakeListsPath` from android autolinking for pure C++ modules. currently, the path is always defaulted to a generated file path in the library. this breaks autolinking when a C++ library doesn't ship with prebuilt codegen files (with `includesGeneratedCode: false`). after this change, it'll only use `cmakeListsPath` from user specified config. this can potentially break existing libraries if they don't specify the path. but the behavior is currently not consistent with how regular turbo modules work. related #2739
28ea5b5 to
65db3ea
Compare
meta-codesync Bot
pushed a commit
to facebook/react-native
that referenced
this pull request
Jun 1, 2026
…tedCode` (#56938) Summary: Currently, pure C++ modules require `includesGeneratedCode: true`, and the library to be shipping codegen files to work. This is inconsistent with regular turbo modules that work with both setups. The issue is in 2 places: 1. CLI returns hardcoded default for C++ modules 2. Autolinking logic doesn't run codegen for C++ modules PR removing hardcoded default from CLI: react-native-community/cli#2799 This change updates the autolinking logic to detect pure C++ libraries without `includesGeneratedCode: true`, run codegen for them and use correct path for CMakeLists based on the codegen output. ## Changelog: [ANDROID] [FIXED] - Fix pure C++ turbo modules not working without `includesGeneratedCode: true` Pull Request resolved: #56938 Test Plan: - create new cpp library: `npx create-react-native-library@latest awesome-library --yes --description "my library" --type turbo-module --languages cpp` - run `yarn example android` and notice that the build works - apply the following patch to remove `includesGeneratedCode: true`: ```patch diff --git a/package.json b/package.json index e3c893a..f41100f 100644 --- a/package.json +++ b/package.json @@ -112,22 +112,16 @@ { "project": "tsconfig.build.json" } - ], - "codegen" + ] ] }, "codegenConfig": { "name": "AwesomeLibrarySpec", "type": "modules", "jsSrcsDir": "src", - "outputDir": { - "ios": "ios/generated", - "android": "android/generated" - }, "android": { "javaPackageName": "com.awesomelibrary" - }, - "includesGeneratedCode": true + } }, "prettier": { "quoteProps": "consistent", diff --git a/react-native.config.js b/react-native.config.js index fef2c32..46f9600 100644 --- a/react-native.config.js +++ b/react-native.config.js @@ -5,7 +5,6 @@ module.exports = { dependency: { platforms: { android: { - cmakeListsPath: 'generated/jni/CMakeLists.txt', cxxModuleCMakeListsModuleName: 'react-native-awesome-library', cxxModuleCMakeListsPath: 'CMakeLists.txt', cxxModuleHeaderName: 'AwesomeLibraryImpl', ``` - run `yarn example android` and notice that the build fails - apply the patch from this PR and from react-native-community/cli#2799 and notice that the module works correctly screenshot from the test library: <img width="360" height="780" alt="Screenshot_1779448311" src="https://github.com/user-attachments/assets/a3f43a3c-bb46-404c-80ff-173ea71a9887" /> Reviewed By: cortinico Differential Revision: D106094034 Pulled By: fabriziocucci fbshipit-source-id: 1d0058907e7a274a8b7de2ec69539dda70bb8f67
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
this removes the incorrect default
cmakeListsPathfrom android autolinking for pure C++ modules.currently, the path is always defaulted to a generated file path in the library. this breaks autolinking when a C++ library doesn't ship with prebuilt codegen files (with
includesGeneratedCode: false).after this change, it'll only use
cmakeListsPathfrom user specified config.this can potentially break existing libraries if they don't specify the path.
but the behavior is currently not consistent with how regular turbo modules work.
the fix for libraries is to specify explicit
cmakeListsPathinreact-native.config.js.this only fixes part of the issue. the autolinking logic in react native also needs to be updated (PR: facebook/react-native#56938)
related #2739
Test Plan
npx create-react-native-library@latest awesome-library --yes --description "my library" --type turbo-module --languages cppyarn example androidand notice that the build worksincludesGeneratedCode: true:yarn example androidand notice that the build failsincludesGeneratedCodefacebook/react-native#56938 and notice that the module works correctlyChecklist
react-nativecheckout (instructions).