Search code examples
xcodecordovaphonegap-pluginscordova-plugins

Cordova plugin.xml add "Header Search Paths" entry


I would like a new entry to be added under "Header Search Paths" once my Cordova plugin is added to an Xcode project.

How can I config it in my Cordova plugin.xml file?

Thanks.


Solution

  • As far as I know, there's no way to do this on a project-wide basis.

    However, there is a way to add to the search path for each of your source files, which accomplishes the same thing. The source-file element in plugin.xml supports a compiler-flags attribute. To this attribute, you may add any flags that the compiler (in this case the clang command) supports. The compiler flag to add to the header search path is -I<path>. Note that if you include a space (eg -I <path>), Cordova will produce a misformatted .xcodeproj folder, and you will not be able to open the project in Xcode, nor build the Cordova project from the command line. Note also that <path> in this case is relative to your .xcodeproj folder that Cordova generates.

    So, for example, if you have these files in your plugin folder (let's call it ~/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"

    You would then want to put into 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 Cordova project. Note again that there must be no space after the -I flag.

    This method unfortunately requires that the developer control both the plugin and the Cordova project. It won't be very useful if you want to publish a plugin for all to use. There is probably a better way to do this; I'd love to hear other solutions.

    Hope that helps!