Skip to content

fix(android): don't hardcode default cmakeListsPath for pure c++ modules#2799

Merged
thymikee merged 1 commit into
mainfrom
@satya164/fix-cpp-default
Jun 1, 2026
Merged

fix(android): don't hardcode default cmakeListsPath for pure c++ modules#2799
thymikee merged 1 commit into
mainfrom
@satya164/fix-cpp-default

Conversation

@satya164
Copy link
Copy Markdown
Member

@satya164 satya164 commented May 22, 2026

Summary

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.
the fix for libraries is to specify explicit cmakeListsPath in react-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

  • 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:
    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 Handle autolinking for pure C++ turbo modules without includesGeneratedCode facebook/react-native#56938 and notice that the module works correctly

Checklist

  • Documentation is up to date.
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, my test plan has linked these CLI changes into a local react-native checkout (instructions).

…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
@satya164 satya164 force-pushed the @satya164/fix-cpp-default branch from 28ea5b5 to 65db3ea Compare May 22, 2026 11:08
@satya164 satya164 marked this pull request as ready for review May 22, 2026 11:34
@satya164 satya164 requested a review from thymikee as a code owner May 22, 2026 11:34
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
@thymikee thymikee merged commit e9f07f7 into main Jun 1, 2026
8 checks passed
@thymikee thymikee deleted the @satya164/fix-cpp-default branch June 1, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants