Skip to content

Commit f86bc95

Browse files
gabrieldonadelcortinico
authored andcommitted
Fix Android autolink plugin for libraries that are platform specific (#45223)
Summary: Fixes #45222 ## Changelog: [ANDROID] [FIXED] - Fix autolink plugin for libraries that are platform-specific Pull Request resolved: #45223 Test Plan: And a library that does not have Android native code such as react-native-segmented-control/segmented-control and sync gradle Reviewed By: rshest Differential Revision: D59221562 Pulled By: cortinico fbshipit-source-id: 55739d63ded63e46897d0d770281f937668c1f50
1 parent 3252855 commit f86bc95

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings
112112

113113
internal fun getLibrariesToAutolink(buildFile: File): Map<String, File> {
114114
val model = JsonUtils.fromAutolinkingConfigJson(buildFile)
115-
return model?.dependencies?.values?.associate { deps ->
116-
":${deps.nameCleansed}" to File(deps.platforms?.android?.sourceDir)
117-
} ?: emptyMap()
115+
return model
116+
?.dependencies
117+
?.values
118+
// We handle scenarios where there are deps that are
119+
// iOS-only or missing the Android configs.
120+
?.filter { it.platforms?.android?.sourceDir != null }
121+
?.associate { deps ->
122+
":${deps.nameCleansed}" to File(deps.platforms?.android?.sourceDir)
123+
} ?: emptyMap()
118124
}
119125

120126
internal fun computeSha256(lockFile: File) =

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,35 @@ class ReactSettingsExtensionTest {
103103
map[":react-native_oss-library-example"])
104104
}
105105

106+
@Test
107+
fun getLibrariesToAutolink_withiOSOnlyLibrary_returnsEmptyMap() {
108+
val validJsonFile =
109+
createJsonFile(
110+
"""
111+
{
112+
"reactNativeVersion": "1000.0.0",
113+
"dependencies": {
114+
"@react-native/oss-library-example": {
115+
"root": "./node_modules/@react-native/oss-library-example",
116+
"name": "@react-native/oss-library-example",
117+
"platforms": {
118+
"ios": {
119+
"podspecPath": "./node_modules/@react-native/oss-library-example/OSSLibraryExample.podspec",
120+
"version": "0.0.1",
121+
"configurations": [],
122+
"scriptPhases": []
123+
}
124+
}
125+
}
126+
}
127+
}
128+
"""
129+
.trimIndent())
130+
131+
val map = getLibrariesToAutolink(validJsonFile)
132+
assertEquals(0, map.keys.size)
133+
}
134+
106135
@Test
107136
fun checkAndUpdateLockfiles_withNothingToCheck_returnsFalse() {
108137
val project = ProjectBuilder.builder().build()

0 commit comments

Comments
 (0)