From 833c3a2cf5df6b65c6fe75577da2df7c5a085e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Mon, 9 Sep 2024 07:22:28 -0700 Subject: [PATCH] fix: RNGP autolink not properly filter out pure C++ TurboModules (#46381) Summary: Hey. The react-native gradle plugin didn't properly filter out [Pure](https://github.com/react-native-community/cli/pull/2387) C++ TurboModules for autolinking, which caused build failures as a non-existing gradle dependency would be emitted. This makes Pure C++ TurboModules work again for Android. ## Changelog: [ANDROID][FIXED] Fix autolinking issues for Pure C++ TurboModules Pull Request resolved: https://github.com/facebook/react-native/pull/46381 Test Plan: https://github.com/hsjoberg/rn75autolinkregression Try running this repro project to observe the error: ``` 1: Task failed with an exception. ----------- * Where: Build file '/Users/coco/Projects/Blixt/rn75autolinkregression/example/android/app/build.gradle' line: 54 * What went wrong: A problem occurred evaluating project ':app'. > Project with path ':react-native-cxx-turbomodule' could not be found in project ':app'. ``` Simply add the 1-line code from this PR to make the build succeed. Cheers. Reviewed By: cipolleschi Differential Revision: D62377757 Pulled By: cortinico fbshipit-source-id: 9e3fa3777b4e6e4d3f2eb0f996ac0ac7676eedbe --- .../com/facebook/react/ReactExtension.kt | 1 + .../com/facebook/react/ReactExtensionTest.kt | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index dcdfc19026dc63..b67e8826b339f5 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -188,6 +188,7 @@ abstract class ReactExtension @Inject constructor(val project: Project) { ?.dependencies ?.values ?.filter { it.platforms?.android !== null } + ?.filterNot { it.platforms?.android?.isPureCxxDependency == true } ?.forEach { deps -> val nameCleansed = deps.nameCleansed val dependencyConfiguration = deps.platforms?.android?.dependencyConfiguration diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt index d1fcb3d216bacd..6340f7fd81a73b 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt @@ -189,6 +189,44 @@ class ReactExtensionTest { assertThat(deps).isEmpty() } + @Test + fun getGradleDependenciesToApply_withIsPureCxxDeps_filtersCorrectly() { + val validJsonFile = + createJsonFile( + """ + { + "reactNativeVersion": "1000.0.0", + "dependencies": { + "@react-native/oss-library-example": { + "root": "./node_modules/@react-native/android-example", + "name": "@react-native/android-example", + "platforms": { + "android": { + "sourceDir": "src/main/java", + "packageImportPath": "com.facebook.react" + } + } + }, + "@react-native/another-library-for-testing": { + "root": "./node_modules/@react-native/cxx-testing", + "name": "@react-native/cxx-testing", + "platforms": { + "android": { + "sourceDir": "src/main/java", + "packageImportPath": "com.facebook.react", + "isPureCxxDependency": true + } + } + } + } + } + """ + .trimIndent()) + + val deps = getGradleDependenciesToApply(validJsonFile) + assertThat(deps).containsExactly("implementation" to ":react-native_android-example") + } + private fun createJsonFile(@Language("JSON") input: String) = tempFolder.newFile().apply { writeText(input) } }