Skip to content

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

Open
satya164 wants to merge 1 commit into
mainfrom
@satya164/fix-cpp-default
Open

fix(android): don't hardcode default cmakeListsPath for pure c++ modules#2799
satya164 wants to merge 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
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.

1 participant