From b5b3f3c43d02dc552c0884f9cee416c68b6eaea2 Mon Sep 17 00:00:00 2001 From: Rui Ying Date: Fri, 10 May 2024 02:51:11 -0700 Subject: [PATCH] Handle the case where the file reference doesn't have a path (#44410) --- .../scripts/cocoapods/privacy_manifest_utils.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb b/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb index aa00f2db6ff..e7c7fda8907 100644 --- a/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb +++ b/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb @@ -67,7 +67,7 @@ module PrivacyManifestUtils end def self.ensure_reference(file_path, user_project, target) - reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path.end_with? "PrivacyInfo.xcprivacy" } + reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" } unless reference_exists # We try to find the main group, but if it doesn't exist, we default to adding the file to the project root – both work file_root = user_project.root_object.main_group.children.first { |group| group.name == target.name } || user_project @@ -76,7 +76,12 @@ module PrivacyManifestUtils end end - def self.get_privacyinfo_file_path(user_project) + def self.get_privacyinfo_file_path(user_project, targets) + file_refs = targets.flat_map { |target| target.resources_build_phase.files_references } + existing_file = file_refs.find { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" } + if existing_file + return existing_file.real_path + end # We try to find a file we know exists in the project to get the path to the main group directory info_plist_path = user_project.files.find { |file_ref| file_ref.name == "Info.plist" } if info_plist_path.nil?