Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you define the target for Specific Build Settings or Adding Frameworks? #54

Open
adam-govan opened this issue May 30, 2019 · 5 comments

Comments

@adam-govan
Copy link

adam-govan commented May 30, 2019

I've made an App Extension with the addTarget function but even though I have the target defined like so :

// (some global paths deliberately left out but they all point correctly)
    var extFiles = [
        'NotificationService.h',
        'NotificationService.m',
        `${extName}-Info.plist`,
        'appgroupconfig.json',
        'PushExtension.entitlements',
    ];

        const proj = xcode.project(projPath);
        proj.parseSync();

        // Copy in the extension files
        fs.mkdirSync(`${iosPath}${extName}`);
        extFiles.forEach(function (extFile) {
            let targetFile = `${iosPath}${extName}/${extFile}`;
            fs.createReadStream(`${sourceDir}${extFile}`)
                .pipe(fs.createWriteStream(targetFile));
        });
        
        // Add a target for the extension
        let extTarget = proj.addTarget(extName, 'app_extension');

I cannot seem to define any buildProperties for it specifically. For example, the function

pbxProject.prototype.updateBuildProperty = function(prop, value, build)

takes in the property key the value and the build but this will only update the main project and not any of the targets defined.

The target parameter in the addFramework function doesn't appear to work either. When digging into the pbxfile that it creates to addToFrameworkSearchPaths the target is not passed or accessed in the constructor. The following code doesn't add the Framework to the target:

var opt = {target: extTarget.uuid, embed: true, customFramework: true, sign: true}
proj.addFramework(`${custom_framework_path}`, opt);

Can somebody please point me to the right direction here? I don't know what I'm doing wrong.

@adam-govan
Copy link
Author

To note: I have added this and got the target membership on xcode of the framework correctly checked:

proj.addBuildPhase( [`${custom_framework_parth}`], 'PBXCopyFilesBuildPhase', 'Embed Frameworks', extTarget.uuid);

however, The Framework Search Path is left blank so the framework is not recognised on xcode compilation.

@brodycj
Copy link

brodycj commented Sep 27, 2019

My apologies for the lack of response. Maintainers are completely overloaded. A PR with test coverage would be much appreciated.

@adam-govan
Copy link
Author

adam-govan commented Oct 10, 2019

that's ok, I've found a workaround by iterating through xcode product names in an after_prepare script and modifying those that match the extension name to have the appropriate framework search path. Here's roughly how (sorry about the formatting):

// Iterate through the entire XCBuildConfig for config of the new target PRODUCT_NAME and modify it
var config = proj.hash.project.objects['XCBuildConfiguration'];
for (var ref in config) {
	if (
		config[ref].buildSettings !== undefined &&
		config[ref].buildSettings.PRODUCT_NAME !== undefined &&
		config[ref].buildSettings.PRODUCT_NAME.includes(extName)
	) {
	  console.log(`entered the setting: ${config[ref].buildSettings.PRODUCT_NAME} of ${ref}`);

	  var INHERITED = '"$(inherited)"';
	  if (!config[ref].buildSettings['FRAMEWORK_SEARCH_PATHS'] || config[ref].buildSettings['FRAMEWORK_SEARCH_PATHS'] === INHERITED) {
		  proj.hash.project.objects['XCBuildConfiguration'][ref].buildSettings['FRAMEWORK_SEARCH_PATHS'] = [INHERITED];
  	}

		// Fix issues with the framework search paths
	  proj.hash.project.objects['XCBuildConfiguration'][ref].buildSettings['FRAMEWORK_SEARCH_PATHS'].push(`"${customFrameworkDirectory}"`);
	}
}

if I figure out where this should fit into cordova-xcode-node I'll make a PR. thanks for your response.

@brodycj
Copy link

brodycj commented Oct 10, 2019

Thanks @adam-govan. I have a dumb question: can you explain the relationship between this issue and #47?

@adam-govan
Copy link
Author

not a dumb question at all! 😄 I started in the same place that #47 was working on, automating a service extension (specifically for push in my case), but I found when adding a Custom Framework to the extension that it wasn't adding to the correct target. It wasn't exactly what #47 was covering so I decided to make my own issue and detail that exactly.

I hope that's ok. I can close if you don't think it's required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants