Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings variable in cordova config.xml for plugin installation

I have a cordova app which needs several plugins and want to configure it using the config.xml file. For instance, i need the 'plugin.google.maps' which needs the following variable when installing : API_KEY_FOR_ANDROID

If i do the following without specifying the plugin in config.xml, this works:

cordova platform add android
cordova plugin add plugin.google.maps --variable API_KEY_FOR_ANDROID="$MYKEY"

It doesn't work if i put in my config.xml file:

<feature name="cordova-plugin-app-version">
    <param name="id" value="plugin.google.maps" />
    <param name="API_KEY_FOR_ANDROID" value="$MYKEY" />
</feature>

and then run

cordova platform add android

I get the following error:

Installing "plugin.google.maps" for android
Failed to install 'plugin.google.maps':Error: Variable(s) missing: API_KEY_FOR_ANDROID
at /usr/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:299:23
at _fulfilled (/usr/lib/node_modules/cordova/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/lib/node_modules/cordova/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/lib/node_modules/cordova/node_modules/q/q.js:749:13)
at /usr/lib/node_modules/cordova/node_modules/q/q.js:557:44
at flush (/usr/lib/node_modules/cordova/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)

I'm having a hard time finding clear documentation on plugin configuration in config.xml. Is it the proper way to do this? What am i missing?

like image 331
Guillaume Thomas Avatar asked Apr 15 '15 08:04

Guillaume Thomas


1 Answers

I think you can do it configuring your plugin as following :

<plugin name="cordova-plugin-app-version">
   <param name="id" value="plugin.google.maps" />
   <variable name="API_KEY_FOR_ANDROID" value="$MYKEY" />
</plugin>

Hope that helps even after all this time ;)

like image 66
akofman Avatar answered Oct 06 '22 13:10

akofman