Cordova plugin.xml adds a Header Search Contours entry

I would like to add a new entry in the Header Search Paths as soon as my Cordova plugin is added to the Xcode project.

How to configure it in a Cordova plugin.xml file?

Thanks.

+7
xcode cordova cordova-plugins phonegap-plugins
source share
3 answers

As far as I know, there is no way to do this based on the whole project.

However, there is a way to add to the search path for each of your source files that does the same thing. The source-file element in plugin.xml supports the compiler-flags attribute. You can add any flags that the compiler supports (in this case, the clang command) to this attribute. Compiler flag to add the -I<path> header to the search -I<path> . Note that if you include a space (for example, -I <path> ), Cordoba will create an incorrectly formed .xcodeproj folder, and you will not be able to open the project in Xcode and will not build the Cordova project from the command line. Also note that the <path> in this case refers to your .xcodeproj folder that Cordova generates.

So, for example, if you have these files in your plugin folder (call ~ / com.MyPlugin /):

 myAngleHeader.h mySource.m mySource.h 

where mySource.h contains the line #include <myAngleHeader.h> and mySource.m contains the line #include "mySource.h"

Then you want to add to your plugin.xml (~ / com.MyPlugin / plugin.xml):

 <source-file src="myAngleHeader.h" /> <source-file src="mySource.h" /> <source-file src="mySource.m" compiler-flags="-ImyApp/Plugins/com.MyPlugin/" /> 

where "myApp" is the name of your project in Cordoba. Once again, there should be no spaces after the -I flag.

This method, unfortunately, requires the developer to control both the plugin and the Cordova project. This will not be very useful if you want to publish the plugin for everyone. There is probably a better way to do this; I would like to hear other solutions.

Hope this helps!

+3
source share

I wanted to update the header search paths through the configuration, as it was always a manual task setting it on the build day. Since then I have added this plugin:

Cordoba-Custom Plugin

Then I was able to add them to my configuration and not worry about it again.

 <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" /> 

+2
source share

@JohnWalthour

I needed to do this for the cordova plugin that I create, and with "after installing the plug-in" is possible. I realized that after installing and modifying HEADER_SEARCH_PATHS in ${project}/platforms/ios/cordova/build.xcconfig I can run the node.js script.

It takes to get dirty, but it works great. One of the most important components of this work is that the Bundle name is assigned ${PRODUCT_NAME} in info.plist, so you can use ${PRODUCT_NAME} in your build.xcconfig and it will interpolate with your project / application name. Cordoba already has a set of ${PRODUCT_NAME} variables for you.

Here is the relevant code -

plugin.xml (abbreviated for brevity and important material)

 <platform name="ios"> ..... <hook type="after_plugin_install" src="hooks/AfterPluginInstall.js" /> <hook type="before_plugin_uninstall" src="hooks/BeforePluginUninstall.js" /> ..... </platform> 

AfterPluginInstall.js

 #!/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'); }); 

BeforePluginUninstall.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'); }); 
+1
source share

All Articles