diff --git a/packages/react-native-gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt b/packages/react-native-gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt index b72f6701f9e..b3e22bd73ad 100644 --- a/packages/react-native-gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt +++ b/packages/react-native-gradle-plugin/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt @@ -112,9 +112,15 @@ abstract class ReactSettingsExtension @Inject constructor(val settings: Settings internal fun getLibrariesToAutolink(buildFile: File): Map { val model = JsonUtils.fromAutolinkingConfigJson(buildFile) - return model?.dependencies?.values?.associate { deps -> - ":${deps.nameCleansed}" to File(deps.platforms?.android?.sourceDir) - } ?: emptyMap() + return model + ?.dependencies + ?.values + // We handle scenarios where there are deps that are + // iOS-only or missing the Android configs. + ?.filter { it.platforms?.android?.sourceDir != null } + ?.associate { deps -> + ":${deps.nameCleansed}" to File(deps.platforms?.android?.sourceDir) + } ?: emptyMap() } internal fun computeSha256(lockFile: File) = diff --git a/packages/react-native-gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt b/packages/react-native-gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt index 21454324253..72d687b2ef5 100644 --- a/packages/react-native-gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt +++ b/packages/react-native-gradle-plugin/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt @@ -103,6 +103,35 @@ class ReactSettingsExtensionTest { map[":react-native_oss-library-example"]) } + @Test + fun getLibrariesToAutolink_withiOSOnlyLibrary_returnsEmptyMap() { + val validJsonFile = + createJsonFile( + """ + { + "reactNativeVersion": "1000.0.0", + "dependencies": { + "@react-native/oss-library-example": { + "root": "./node_modules/@react-native/oss-library-example", + "name": "@react-native/oss-library-example", + "platforms": { + "ios": { + "podspecPath": "./node_modules/@react-native/oss-library-example/OSSLibraryExample.podspec", + "version": "0.0.1", + "configurations": [], + "scriptPhases": [] + } + } + } + } + } + """ + .trimIndent()) + + val map = getLibrariesToAutolink(validJsonFile) + assertEquals(0, map.keys.size) + } + @Test fun checkAndUpdateLockfiles_withNothingToCheck_returnsFalse() { val project = ProjectBuilder.builder().build()