A framework for building native applications using React
Handle autolinking for pure C++ turbo modules without `includesGeneratedCode` (#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: https://github.com/react-native-community/cli/pull/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: https://github.com/facebook/react-native/pull/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 https://github.com/react-native-community/cli/pull/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 S
Satyajit Sahoo committed
c7898805178dd7881c745185a5915ce2c4cf3c1d
Parent: f363f6b
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com>
on 6/1/2026, 10:23:20 AM