Skip to content

Incorrect default value for cmakeListsPath in pure C++ TurboModules #2739

Description

@arcticfox1919

Description

The dependencyConfig function in packages/cli-config-android/src/config/index.ts sets an incorrect default value for cmakeListsPath that applies to all dependencies, including pure C++ TurboModules. This causes build failures in host applications when the default path doesn't exist.

Current Behavior

The code currently sets cmakeListsPath to a hardcoded default path without considering whether the module is a pure C++ dependency:

// packages/cli-config-android/src/config/index.ts (lines 168-170)letcmakeListsPath=userConfig.cmakeListsPath
? path.join(sourceDir,userConfig.cmakeListsPath)
: path.join(sourceDir,'build/generated/source/codegen/jni/CMakeLists.txt');

Problem: This default path assumes all modules use Codegen and generate files to build/generated/source/codegen/jni/. However, for pure C++ TurboModules that don't use Codegen or use a custom output directory, this path does not exist.

Additional Evidence from React Native Gradle Plugin Source Code:
I've reviewed the React Native Gradle Plugin source code at react-native/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateAutolinkingNewArchitecturesFileTask.kt:

if (libraryName !=null&& cmakeListsPath !=null) {
val nativeFolderPath = sanitizeCmakeListsPath(cmakeListsPath)
addDirectoryString +="add_subdirectory(\"$nativeFolderPath\"${libraryName}_autolinked_build)"
}
if (cxxModuleCMakeListsPath !=null) {
val nativeFolderPath = sanitizeCmakeListsPath(cxxModuleCMakeListsPath)
addDirectoryString +="\nadd_subdirectory(\"$nativeFolderPath\"${libraryName}_cxxmodule_autolinked_build)"
}

Key Finding: For pure C++ TurboModules, cmakeListsPath and cxxModuleCMakeListsPath should be mutually exclusive. Only one of them should be set:

  • cmakeListsPath: For Codegen-generated CMakeLists.txt (regular TurboModules)
  • cxxModuleCMakeListsPath: For custom CMakeLists.txt (pure C++ TurboModules)

However, the current CLI implementation always sets cmakeListsPath to a default value, even for pure C++ TurboModules. This results in both paths being set simultaneously, which is incorrect and may cause unexpected behavior during the autolinking process.

Proposed Fix

// packages/cli-config-android/src/config/index.tsletcmakeListsPath: string|null;if(userConfig.cmakeListsPath!==undefined){// User explicitly configured it (including null)cmakeListsPath=userConfig.cmakeListsPath
? path.join(sourceDir,userConfig.cmakeListsPath)
: null;}else{// Apply default only for non-pure-C++ modulescmakeListsPath=isPureCxxDependency
? null// Pure C++ modules don't need Codegen CMakeLists.txt by default
: path.join(sourceDir,'build/generated/source/codegen/jni/CMakeLists.txt');}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions