I want to use a Cordova plugin that uses Swift code, so it has to insert a bridging header and set some other build options. It does so, by adding a platform hook like this to config.xml:
<hook type="after_platform_add" src="hooks/setup-hook.js" />
There seems to be no option in the mobile-config.js file to do add this kind of stuff. So the only way I can see in Meteor to add such a hook, would be to create a
cordova-build-override folder, put the hook there, and then also place a custom config.xml file in this folder as well. But in this case, I would lose the automatism provided by mobile-config.js.
But maybe there is an undocumented way of doing this better. Maybe I missed something?
You may want to have a look at the way I’ve done this for
cordova-plugin-meteor-webapp, which is also written in Swift. It uses an
after-plugin-install hook to execute a script that modifies the bridging header to add an extra
#include for a plugin-specific bridging header.
There may be other ways of doing this. You can actually modify
config.xml from a
<config-file target="config.xml" parent="/*">), although I’m not sure if you can add hooks that way.
Thanks a lot for your fast reply. I will try this approach!
From another post of yours, I know that you also patched the bitcode settings once. I tried the
akofman/cordova-plugin-disable-bitcode plugin for this, but it did not work with Meteor. So I would be glad if you could point me to your bitcode patching code as well. Thanks in advance!
I don’t actually remember commenting on bitcode settings, and I haven’t made any changes to them myself.
Are you using Meteor 1.2 or 1.3 beta? From the
cordova-plugin-disable-bitcode plugin change history it seems support for older Corodva versions (like the one bundled with Meteor 1.2) was only just added. So you may want to try again with the most recent version.
Ah, ok, then I remembered this incorrectly I thought I read that you had disabled Bitcode for 1.3 by default.
I tried this version, but it did not work either.
I’ve now tried to modify Xcode build settings via a script using the
In principle it works, I can see that the Xcode project file is modified correctly (I’ve watched the changes in my editor while the Cordova plugins are being installed). But all of a sudden, all changes to the project file are reverted.
This happens when the following step is executed during the build process: “Preparing Cordova project for platform iOS” (visible with meteor --verbose).
If I change the hook to
after_prepare, my changes are not reverted. So for my own code, I could workaround that. But this reversion also affects other Cordova plugins like https://github.com/akofman/cordova-plugin-disable-bitcode, so it seems to be a more general problem.
Do you happen to know what exactly happens during this preparation phase and why this might revert changes already saved to the filesystem?
The step you mention is similar to running
cordova prepare ios. That is when the Xcode project is generated/updated and the
www assets are copied to the platform-specific directory.
I’m not sure which build settings are overwritten by that, but for a script in
cordova-plugin-meteor-webapp I’ve used a
before_prepare hook instead of an
thanks for your reply. As far as I can tell, the Xcode project is created long before this step runs, so I think it’s an update step that does something weird here.
Yes, I’ve seen in your code that you’re changing some Xcode settings in your plugin, but AFAIK this plugin is only used from 1.3 on, right? I’m still on 1.2, so this shouldn’t be the culprit here. But I’ve seen in another plugin that the author recommended to use Xcode.parseSync() instead of Xcode.parse(), since the latter might cause troubles if several plugins try to modify the settings. Maybe you’d like to change that.
Because I already thought there might be a plugin that runs a hook in the preparation phase, I also did a grep through all plugins that are added to my app, but none of them had such hooks (only hooks that run after plugin install). Are there any “hidden” plugins that you cannot see in Meteor’s Cordova build folder that I am not aware of?
Yes, the plugin is only used on 1.3. But I didn’t mention it because I thought it might be the culprit, but as an example of modifying settings in a
before_prepare hook. Have you tried that instead of
All installed plugins should be listed in the
cordova-build directory, so I don’t think there are any hidden plugins.
Thanks for the tip about
Xcode.parseSync. I’ll have a look at it.
Yes, as I said above, changing the hook to before_prepare worked as a workaround. But: this only solves the problem for my own custom plugins, it does not solve it for 3rd party plugins that rely on after_plugin_install. I’ve actually seen that some of my plugins use this to modify Xcode settings, but all of these changes are reverted once the prepare step is executed. So this seems to be a general problem for me.
BTW and just for the records: I’ve also tried to place hooks in the cordova-build-override folder and add them to a custom config.xml. Yet I found out that hooks added this way would never be executed. Hooks only work if they are part of a plugin.