Xcode Cordova plugin.xml添加";标题搜索路径“;进入

Xcode Cordova plugin.xml添加";标题搜索路径“;进入,xcode,cordova,phonegap-plugins,cordova-plugins,Xcode,Cordova,Phonegap Plugins,Cordova Plugins,我想在我的Cordova插件添加到Xcode项目后,在“标题搜索路径”下添加一个新条目 如何在Cordova plugin.xml文件中配置它 谢谢。据我所知,在整个项目范围内无法做到这一点 但是,有一种方法可以添加到每个源文件的搜索路径中,从而完成相同的任务。plugin.xml中的元素支持编译器标志属性。对于该属性,您可以添加编译器(在本例中为clang命令)支持的任何标志。要添加到标头搜索路径的编译器标志是-I。请注意,如果包含空格(例如-I),Cordova将生成格式错误的.xcodep

我想在我的Cordova插件添加到Xcode项目后,在“标题搜索路径”下添加一个新条目

如何在Cordova plugin.xml文件中配置它


谢谢。

据我所知,在整个项目范围内无法做到这一点

但是,有一种方法可以添加到每个源文件的搜索路径中,从而完成相同的任务。plugin.xml中的元素支持
编译器标志
属性。对于该属性,您可以添加编译器(在本例中为
clang
命令)支持的任何标志。要添加到标头搜索路径的编译器标志是
-I
。请注意,如果包含空格(例如
-I
),Cordova将生成格式错误的
.xcodeproj
文件夹,您将无法在Xcode中打开项目,也无法从命令行生成Cordova项目。还要注意,在这种情况下,
与Cordova生成的
.xcodeproj
文件夹相关

例如,如果您的插件文件夹中有这些文件(我们称之为~/com.MyPlugin/):

其中
mySource.h
包含行
#include
mySource.m
包含行
#include“mySource.h”

然后,您需要将以下内容放入plugin.xml(~/com.MyPlugin/plugin.xml):


其中“myApp”是您的Cordova项目的名称。再次注意,
-I
标志后不得有空格

不幸的是,这种方法要求开发人员同时控制插件和Cordova项目。如果你想发布一个供所有人使用的插件,它就没有多大用处了。也许有更好的方法可以做到这一点;我想听听其他的解决办法

希望有帮助

@JohnWalthour

我需要为我正在创建的cordova插件做这件事,使用这个钩子是可能的。我意识到我可以在安装和修改
${project}/platforms/ios/cordova/build.xcconfig
中的
标题搜索路径后运行node.js脚本

它需要弄脏,但效果很好。这项工作的一个关键部分是将捆绑包名称分配给info.plist中的
${PRODUCT\u name}
,这样您就可以在
build.xcconfig
中使用
${PRODUCT\u name}
,它将插入您的项目/应用程序名称。Cordova已经为您设置了
${PRODUCT_NAME}
变量

以下是有关守则-

plugin.xml(为了简洁和重要的东西而缩短)

beforeplugininstall.js

#!/usr/bin/env node
'use strict';

let cwd = process.cwd();
let fs = require('fs');
let path = require('path');

console.log('InstagramAssetsPicker BeforePluginInstall.js, attempting to modify build.xcconfig');

let xcConfigBuildFilePath = path.join(cwd, 'platforms', 'ios', 'cordova', 'build.xcconfig');
console.log('xcConfigBuildFilePath: ', xcConfigBuildFilePath);
let lines = fs.readFileSync(xcConfigBuildFilePath, 'utf8').split('\n');

let headerSearchPathLineNumber;
lines.forEach((l, i) => {
  if (l.indexOf('HEADER_SEARCH_PATHS') > -1) {
    headerSearchPathLineNumber = i;
  }
});

if (lines[headerSearchPathLineNumber].indexOf('InstagramAssetsPicker') === -1) {
  console.log('build.xcconfig does not have header path for InstagramAssetsPicker.');
  return;
}

let line = lines[headerSearchPathLineNumber];
lines[headerSearchPathLineNumber] = line.replace(/\ "\$\(SRCROOT\)\/\$\(PRODUCT_NAME\)\/cordova-plugin-InstagramAssetsPicker\/GPUImageHeaders\"/i, '');

let newConfig = lines.join('\n');

fs.writeFile(xcConfigBuildFilePath, newConfig, function (err) {
  if (err) {
    console.log('error updating build.xcconfig, err: ', err);
    return;
  }
  console.log('successfully updated HEADER_SEARCH_PATHS in build.xcconfig');
});

我想通过配置更新我的标题搜索路径,因为在构建日设置它总是一项手动任务。我添加了这个插件:

然后我就可以将这些添加到我的配置中,而不必再担心了

<platform name="ios">
   <!-- Set orientation on iPhone -->
   <config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations">
     <array>
       <string>UIInterfaceOrientationPortrait</string>
       <string>UIInterfaceOrientationPortraitUpsideDown</string>
     </array>
   </config-file>
   <!-- Set orientation on iPad -->
   <config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations~ipad">
     <array>
       <string>UIInterfaceOrientationLandscapeLeft</string>
       <string>UIInterfaceOrientationLandscapeRight</string>
     </array>
   </config-file>
   <!-- Set Header Search Paths-->
   <preference name="ios-XCBuildConfiguration-HEADER\_SEARCH\_PATHS" value="'$(TARGET_BUILD_DIR)/usr/local/lib/include' '$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include' '$(BUILT_PRODUCTS_DIR)'" buildType="release" xcconfigEnforce="true" />

UIInterfaceOrientationPortrait
UIInterfaceOrientation上下方向图
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight

这正是我一直在寻找的,谢谢。我只是想问一下,是否可以添加多个编译器标志?因为我还需要将编译器标志'-fno objc arc'添加到相同的文件中。我打赌你可以,但我自己还没有尝试过。尝试将编译器标志的完整列表放入该元素-例如compiler flags=“-I/folder/-fno obj arc”或类似的内容。但由于空间的原因,它可能会产生问题。@JohnWalthour嘿,我想出了一个办法,在下面给出了答案。不确定@回复是否在帖子中起作用。完成后,我将与您分享我的插件,它非常接近。@AlonAmir这里是我的cordova插件,它使用钩子修改插件安装/卸载的标题搜索路径-太棒了!这听起来像是一个解决方案,可以让你的插件更加便携。
<platform name="ios">
  .....
  <hook type="after_plugin_install" src="hooks/AfterPluginInstall.js" />
  <hook type="before_plugin_uninstall" src="hooks/BeforePluginUninstall.js" />
  .....
</platform>
#!/usr/bin/env node
'use strict';

let cwd = process.cwd();
let fs = require('fs');
let path = require('path');

console.log('InstagramAssetsPicker AfterPluginInstall.js, attempting to modify build.xcconfig');

let xcConfigBuildFilePath = path.join(cwd, 'platforms', 'ios', 'cordova', 'build.xcconfig');
console.log('xcConfigBuildFilePath: ', xcConfigBuildFilePath);
let lines = fs.readFileSync(xcConfigBuildFilePath, 'utf8').split('\n');

let headerSearchPathLineNumber;
lines.forEach((l, i) => {
  if (l.indexOf('HEADER_SEARCH_PATHS') > -1) {
    headerSearchPathLineNumber = i;
  }
});

if (lines[headerSearchPathLineNumber].indexOf('InstagramAssetsPicker') > -1) {
  console.log('build.xcconfig already setup for InstagramAssetsPicker');
  return;
}

lines[headerSearchPathLineNumber] += ' "$(SRCROOT)/$(PRODUCT_NAME)/cordova-plugin-InstagramAssetsPicker/GPUImageHeaders"';

let newConfig = lines.join('\n');

fs.writeFile(xcConfigBuildFilePath, newConfig, function (err) {
  if (err) {
    console.log('error updating build.xcconfig, err: ', err);
    return;
  }
  console.log('successfully updated HEADER_SEARCH_PATHS in build.xcconfig');
});
#!/usr/bin/env node
'use strict';

let cwd = process.cwd();
let fs = require('fs');
let path = require('path');

console.log('InstagramAssetsPicker BeforePluginInstall.js, attempting to modify build.xcconfig');

let xcConfigBuildFilePath = path.join(cwd, 'platforms', 'ios', 'cordova', 'build.xcconfig');
console.log('xcConfigBuildFilePath: ', xcConfigBuildFilePath);
let lines = fs.readFileSync(xcConfigBuildFilePath, 'utf8').split('\n');

let headerSearchPathLineNumber;
lines.forEach((l, i) => {
  if (l.indexOf('HEADER_SEARCH_PATHS') > -1) {
    headerSearchPathLineNumber = i;
  }
});

if (lines[headerSearchPathLineNumber].indexOf('InstagramAssetsPicker') === -1) {
  console.log('build.xcconfig does not have header path for InstagramAssetsPicker.');
  return;
}

let line = lines[headerSearchPathLineNumber];
lines[headerSearchPathLineNumber] = line.replace(/\ "\$\(SRCROOT\)\/\$\(PRODUCT_NAME\)\/cordova-plugin-InstagramAssetsPicker\/GPUImageHeaders\"/i, '');

let newConfig = lines.join('\n');

fs.writeFile(xcConfigBuildFilePath, newConfig, function (err) {
  if (err) {
    console.log('error updating build.xcconfig, err: ', err);
    return;
  }
  console.log('successfully updated HEADER_SEARCH_PATHS in build.xcconfig');
});
<platform name="ios">
   <!-- Set orientation on iPhone -->
   <config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations">
     <array>
       <string>UIInterfaceOrientationPortrait</string>
       <string>UIInterfaceOrientationPortraitUpsideDown</string>
     </array>
   </config-file>
   <!-- Set orientation on iPad -->
   <config-file platform="ios" target="*-Info.plist" parent="UISupportedInterfaceOrientations~ipad">
     <array>
       <string>UIInterfaceOrientationLandscapeLeft</string>
       <string>UIInterfaceOrientationLandscapeRight</string>
     </array>
   </config-file>
   <!-- Set Header Search Paths-->
   <preference name="ios-XCBuildConfiguration-HEADER\_SEARCH\_PATHS" value="'$(TARGET_BUILD_DIR)/usr/local/lib/include' '$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include' '$(BUILT_PRODUCTS_DIR)'" buildType="release" xcconfigEnforce="true" />