diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index d805dabe31c9c7..47e24225bd4aec 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -129,9 +129,9 @@ abstract class ReactExtension @Inject constructor(project: Project) { /** * The root directory for all JS files for the app. * - * Default: [root] (i.e. ${rootProject.dir}/../) + * Default: the parent folder of the `/android` folder. */ - val jsRootDir: DirectoryProperty = objects.directoryProperty().convention(root.get()) + val jsRootDir: DirectoryProperty = objects.directoryProperty() /** * The library name that will be used for the codegen artifacts. diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 8fd0a54dbd3932..48fff59c790a38 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -110,6 +110,15 @@ class ReactPlugin : Plugin { // First, we set up the output dir for the codegen. val generatedSrcDir = File(project.buildDir, "generated/source/codegen") + // We specify the default value (convention) for jsRootDir. + // It's the root folder for apps (so ../../ from the Gradle project) + // and the package folder for library (so ../ from the Gradle project) + if (isLibrary) { + extension.jsRootDir.convention(project.layout.projectDirectory.dir("../")) + } else { + extension.jsRootDir.convention(extension.root) + } + val buildCodegenTask = project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) { it.codegenDir.set(extension.codegenDir)