Skip to content

Commit 833c3a2

Browse files
hsjobergfacebook-github-bot
authored andcommitted
fix: RNGP autolink not properly filter out pure C++ TurboModules (#46381)
Summary: Hey. The react-native gradle plugin didn't properly filter out [Pure](react-native-community/cli#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: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID][FIXED] Fix autolinking issues for Pure C++ TurboModules Pull Request resolved: #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
1 parent 143f1ad commit 833c3a2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
188188
?.dependencies
189189
?.values
190190
?.filter { it.platforms?.android !== null }
191+
?.filterNot { it.platforms?.android?.isPureCxxDependency == true }
191192
?.forEach { deps ->
192193
val nameCleansed = deps.nameCleansed
193194
val dependencyConfiguration = deps.platforms?.android?.dependencyConfiguration

packages/gradle-plugin/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactExtensionTest.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,44 @@ class ReactExtensionTest {
189189
assertThat(deps).isEmpty()
190190
}
191191

192+
@Test
193+
fun getGradleDependenciesToApply_withIsPureCxxDeps_filtersCorrectly() {
194+
val validJsonFile =
195+
createJsonFile(
196+
"""
197+
{
198+
"reactNativeVersion": "1000.0.0",
199+
"dependencies": {
200+
"@react-native/oss-library-example": {
201+
"root": "./node_modules/@react-native/android-example",
202+
"name": "@react-native/android-example",
203+
"platforms": {
204+
"android": {
205+
"sourceDir": "src/main/java",
206+
"packageImportPath": "com.facebook.react"
207+
}
208+
}
209+
},
210+
"@react-native/another-library-for-testing": {
211+
"root": "./node_modules/@react-native/cxx-testing",
212+
"name": "@react-native/cxx-testing",
213+
"platforms": {
214+
"android": {
215+
"sourceDir": "src/main/java",
216+
"packageImportPath": "com.facebook.react",
217+
"isPureCxxDependency": true
218+
}
219+
}
220+
}
221+
}
222+
}
223+
"""
224+
.trimIndent())
225+
226+
val deps = getGradleDependenciesToApply(validJsonFile)
227+
assertThat(deps).containsExactly("implementation" to ":react-native_android-example")
228+
}
229+
192230
private fun createJsonFile(@Language("JSON") input: String) =
193231
tempFolder.newFile().apply { writeText(input) }
194232
}

0 commit comments

Comments
 (0)