cordova-node-xcode icon indicating copy to clipboard operation
cordova-node-xcode copied to clipboard

pbxProject.prototype.addFramework: automatically create Frameworks Group if it does not exist

Open n1ru4l opened this issue 6 years ago • 4 comments

This is a feature proposal

Initial Situation:

Your xcode project tree looks like this: bildschirmfoto 2018-12-09 um 22 28 11

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:

bildschirmfoto 2018-12-09 um 22 15 28

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:

bildschirmfoto 2018-12-09 um 22 23 26

Current workaround:

Add the Frameworks group to mainGroupmanually:

  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!

n1ru4l avatar Dec 09 '18 21:12 n1ru4l

Idk actually if this is a bug or intended behaviour

n1ru4l avatar Dec 09 '18 21:12 n1ru4l

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?

brody4hire avatar Dec 09 '18 22:12 brody4hire

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.

n1ru4l avatar Dec 09 '18 22:12 n1ru4l

[...] 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.

brody4hire avatar Dec 09 '18 22:12 brody4hire