Skip to content

Commit e3a8367

Browse files
authored
fix(#81): crash when adding Settings.bundle (#94)
1 parent 6ffc533 commit e3a8367

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

packages/react-native-legal/bare-plugin/src/ios/addSettingsBundle.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ export function addSettingsBundle(iosProjectPath: string) {
1212
const projectName = getIOSProjectName(iosProjectPath);
1313
const { pbxproj, pbxprojPath } = getIOSPbxProj(iosProjectPath);
1414

15-
pbxproj.removeFile(settingsBundleFilename, pbxproj.findPBXGroupKey({ name: projectName }));
15+
let group: string | undefined = pbxproj.findPBXGroupKey({ name: projectName });
1616

17-
const settingsBundleFile = pbxproj.addFile(settingsBundleFilename, pbxproj.findPBXGroupKey({ name: projectName }));
17+
if (!group) {
18+
// https://github.com/callstackincubator/react-native-legal/issues/81
19+
// If the project name is wrapped in quotes inside pbxproj file, let's try to grab it
20+
group = pbxproj.findPBXGroupKey({ name: `"${projectName}"` });
21+
}
22+
23+
if (!group) {
24+
throw new Error(`Could not find group named: ${projectName} in the pbxproj`);
25+
}
26+
27+
pbxproj.removeFile(settingsBundleFilename, group);
28+
29+
const settingsBundleFile = pbxproj.addFile(settingsBundleFilename, group);
1830

1931
if (!settingsBundleFile) {
2032
throw new Error('Could not add Settings.bundle file reference to xcode project');

0 commit comments

Comments
 (0)