1

我希望能够构建我的项目并在 Xcode 中打开它,而无需通过 Xcode UI 手动设置变量。我开始使用 Cordova 的 buildConfig 参数来指定一些设置(尤其是使用旧版构建系统并设置 Swift 版本),这适用于命令行构建,但它们不会延续到 Xcode 项目文件中。

我正在使用自定义挂钩来修改我的 project.pbxproj 文件中的构建设置,但我希望这不是必需的 - 只是弄清楚设置被称为什么以及它在哪个文件中是一件痛苦的事情。

我无法在 Cordova 文档中找到它,所以我问... Cordova 是否有办法在 Xcode 中保留这些构建设置?

4

2 回答 2

0

Cordova 本身不支持对 Xcode 项目文件 ( project.pbxproj) 的直接操作,但您可以使用cordova-custom-config来执行此操作。

将其作为插件添加到您的项目中:

cordova plugin add cordova-custom-config

然后将一个添加<custom-preference>到您的项目config.xml中,例如:

<custom-preference name="ios-XCBuildConfiguration-SWIFT_VERSION" value="2.3" />

目前cordova-custom-config仅支持对XCBuildConfiguration块的操作。但是,使用xcodefunc首选项,您可以直接调用cordova-node-xcode的pbxProject 接口的函数,这使您能够做一些额外的事情(尽管该接口当前没有记录,所以您必须查看代码),对于例子:

<custom-preference name="ios-xcodefunc" func="addResourceFile">
    <arg type="String" value="src/content/image.png" flag="path" />
</custom-preference>

cordova-custom-config将使用 Cordova 构建生命周期挂钩应用配置,以确保更改保留在本机 Xcode 项目中。

于 2018-11-22T14:26:44.250 回答
0

You said that you tried using a custom hook, and this method is completely valid. You do not have to manually edit the file yourself if that is what you were doing. Using a hook and using the xcode npm package will make this a lot easier. In this case you only need to specify the key and value you want to change in the project file. If you want to change your workspace configuration (build system options) you would want to use the plist npm package. Using these tools it might be less of a pain for you, if you find it easier than the other answer posted.

Example editing the project:

var xcode = require('xcode'),
    fs = require('fs'),
    plist = require('plist'),
    projectPath = 'myproject.xcodeproj/project.pbxproj',
    workspacePath = 'myproject.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings',
    myProj = xcode.project(projectPath);

myProj = myProj.parseSync();

// Add variable
myProj.AddBuildProperty('DEVELOPMENT_TEAM', 'XXXX', 'Debug');

// Save project file
fs.writeFileSync(projectPath, myProj.writeSync());

// Change workspace settings (build system)
fs.writeFileSync(workspacePath, plist.build({"BuildSystemType": "Original"}));
于 2018-11-22T16:48:19.917 回答