cordova-node-xcode
cordova-node-xcode copied to clipboard
How do you define the target for Specific Build Settings or Adding Frameworks?
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.
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.
My apologies for the lack of response. Maintainers are completely overloaded. A PR with test coverage would be much appreciated.
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.
Thanks @adam-govan. I have a dumb question: can you explain the relationship between this issue and #47?
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