Skip to content

Commit 1bec961

Browse files
Irfanwanifacebook-github-bot
authored andcommitted
fix: post install error in iOS after running pod install, undefined method 'path' for nil:NilClass (facebook#45095)
Summary: After upgrading my project to the latest version of react native i.e, 0.74.2, i was getting an error when running `pod install` an the error was coming from the post install hook. Going deeper into the file tree, i found that some of the things are Nil and react native is trying to use some methods on them, so fixed those issues by using chaining operators to conditionally apply the path method on them. ## Changelog: [Internal] - fixes the post install issue when running pod install with react native version, 0.74.2 Pull Request resolved: facebook#45095 Test Plan: Manually tested the fix. Works perfectly fine in both debug and production mode. Reviewed By: cortinico Differential Revision: D58863666 Pulled By: cipolleschi fbshipit-source-id: 64459711dcf926b7544b99b542e9861c1c0f05ca
1 parent a7b2555 commit 1bec961

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,34 @@ def self.read_privacyinfo_file(file_path)
6767
end
6868

6969
def self.ensure_reference(file_path, user_project, target)
70-
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
70+
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref&.path&.end_with? "PrivacyInfo.xcprivacy" }
7171
unless reference_exists
7272
# 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
73-
file_root = user_project.root_object.main_group.children.find { |group| group.class == Xcodeproj::Project::Object::PBXGroup && (group.name == target.name || group.path == target.name) } || user_project
73+
file_root = user_project.root_object.main_group.children.find { |group|
74+
group.class == Xcodeproj::Project::Object::PBXGroup && (group.name == target.name || group.path == target.name)
75+
} || user_project
7476
file_ref = file_root.new_file(file_path)
7577
build_file = target.resources_build_phase.add_file_reference(file_ref, true)
7678
end
7779
end
7880

7981
def self.get_privacyinfo_file_path(user_project, targets)
82+
8083
file_refs = targets.flat_map { |target| target.resources_build_phase.files_references }
81-
existing_file = file_refs.find { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
84+
existing_file = file_refs.find { |file_ref| file_ref&.path&.end_with?("PrivacyInfo.xcprivacy") }
85+
86+
8287
if existing_file
8388
return existing_file.real_path
8489
end
90+
8591
# We try to find a file we know exists in the project to get the path to the main group directory
8692
info_plist_path = user_project.files.find { |file_ref| file_ref.name == "Info.plist" }
8793
if info_plist_path.nil?
8894
# return path that is sibling to .xcodeproj
95+
8996
path = user_project.path
97+
9098
return File.join(File.dirname(path), "PrivacyInfo.xcprivacy")
9199
end
92100
return File.join(File.dirname(info_plist_path.real_path),"PrivacyInfo.xcprivacy")
@@ -117,14 +125,15 @@ def self.get_used_required_reason_apis(installer)
117125
end
118126
end
119127
end
128+
120129
return used_apis
121130
end
122131

123132
def self.get_privacy_manifest_paths_from(user_project)
124133
privacy_manifests = user_project
125134
.files
126135
.select { |p|
127-
p.path&.end_with?('PrivacyInfo.xcprivacy')
136+
p&.path&.end_with?('PrivacyInfo.xcprivacy')
128137
}
129138
return privacy_manifests
130139
end
@@ -162,7 +171,7 @@ def self.add_privacy_manifest_if_needed(installer)
162171
"NSPrivacyTracking" => false,
163172
"NSPrivacyAccessedAPITypes" => get_core_accessed_apis
164173
}
165-
path = File.join(user_project.path.parent, "PrivacyInfo.xcprivacy")
174+
path = File.join(user_project&.path.parent, "PrivacyInfo.xcprivacy")
166175
Xcodeproj::Plist.write_to_path(privacy_manifest, path)
167176
Pod::UI.puts "Your app does not have a privacy manifest! A template has been generated containing Required Reasons API usage in the core React Native library. Please add the PrivacyInfo.xcprivacy file to your project and complete data use, tracking and any additional required reasons your app is using according to Apple's guidance: https://developer.apple.com/documentation/bundleresources/privacy_manifest_files. Then, you will need to manually add this file to your project in Xcode.".red
168177
end

0 commit comments

Comments
 (0)