cordova-node-xcode
cordova-node-xcode copied to clipboard
pbxProject.prototype.addFramework: automatically create Frameworks Group if it does not exist
This is a feature proposal
Initial Situation:
Your xcode project tree looks like this:
You have a Xcode project without a Framworks
group and you want to add a new framework using pbxProject.prototype.addFramework
.
Current behaviour:
The Frameworks
group is created but not added to the mainGroup
of the project which references all files (that are not part of a subgroup) and all groups (that are no subgroups).
If you open the updated xcode project with xcode you see the following:

This is because xcode cannot find a reference to the Frameworks
group on the mainGroup
and therefore "autofixes" the project by adding the library added with pbxProject.prototype.addFramework
to a newly generated group Recovered References
.
Expected behaviour:
The Framework
group is created and also automatically added to the mainGroup
.
When you open the project in xcode it should look like this:

Current workaround:
Add the Frameworks
group to mainGroup
manually:
const project = xcode.project(projectPath);
project.parseSync();
project.addFramework(path.resolve(frameworksDirectory, 'GoogleInterchangeUtilities.framework'), {
customFramework: true,
embed: true,
link: true,
});
const mainProject = project.getPBXGroupByKey(project.getFirstProject().firstProject.mainGroup);
if (!mainProject.children.some(children => children.comment === 'Frameworks')) {
const [groupKey] = Object.entries(project.hash.project.objects['PBXGroup']).find(
([, group]) => group.name === 'Frameworks',
);
project.addToPbxGroup(groupKey, project.getFirstProject().firstProject.mainGroup);
}
If you are okay with this feature proposal I would love to implement it!
Idk actually if this is a bug or intended behaviour
I think we never encountered an issue with this since we would always create the iOS or mac osx project from a template with Frameworks
group already in the right place.
I like the idea of fixing this but would love to better understand the need and use case. How is your Xcode project initially created?
If you are using this in an open-source project can you give us a pointer?
Actually it is a project that was created using npx react-native-cli init TestApp
but modified a.k.a the Frameworks
group was dropped.
I just tried setting up a new project using Xcode and it has not Frameworks
group.
I am currently building a CLI tool for react-native-camera
that downloads necessary libraries and adds those to the Frameworks
group. If a user previously accidentally deleted that group that would also fit the use case.
[...] I just tried setting up a new project using Xcode and it has not
Frameworks
group.
Got it. This looks not quite standard for React Native. According to https://facebook.github.io/react-native/docs/native-modules-ios#native-module-setup is that native modules would normally be distributed as npm packages, which the React Native tooling would import when you build an application.
But we should do something better than putting frameworks into a "Recovered References" group, as proposed here.