const property = new SDK.PluginProperty("integer", "test-property", 0);
this._info.SetProperties([
property
]);
this._info.AddCordovaPluginReference({
id: "cordova-plugin-inappbrowser",
plugin: this,
variables: [
["MY_VAR", property]
]
});
See Cordova plugin variables for more information.
The options object uses the following properties.
- id
- The ID of the Cordova plugin to reference.
- version Optional
- A version spec for the Cordova plugin, e.g.
"1.0.4"
. If this is not specified, the latest version will be used.
- platform Optional
- Specify a specific platform the Cordova plugin applies to. By default this is
"all"
meaning it will be used in both Android and iOS exports. However it can be set to "android"
or "ios"
to only be included when exporting to a specific platform. This is useful to switch between different Cordova plugins on different platforms.
- variables Optional
- Specify variables to be used with the Cordova plugin as an array of
[variableName, pluginProperty]
pairs. The variable name is bound to a SDK.PluginProperty
. When the project is exported a variable is added under the plugin reference in config.xml with the given name and a value taken from the specified property. When variables are specified, the plugin
property must also be set.
- plugin Optional
- Used to specify the plugin when using variables. Normally this should be set to
this
.
Note for security reasons the Construct mobile app build service does not allow arbitrary Cordova plugins to be used. The build service uses an allowlist of allowed Cordova plugins. If you'd like a Cordova plugin to be added to the allowlist, please file an issue on the Construct issue tracker. Please note we cannot guarantee that Cordova plugins will be allowed, and approval is subject to a security review. Other build systems, including compiling with the Cordova CLI, do not impose this restriction.
Cordova resource file dependencies
Addons can further specify dependencies on additional resource files for Cordova exports. When exporting a Cordova project, the additional Cordova resource file dependencies are automatically included in the exported config.xml as <resource file src="..." target="...">
tags.
To add a Cordova resource file dependency, call AddCordovaResourceFile
with an options object, such as in this example:
this._info.AddCordovaResourceFile({
src: "myfile.txt"
});
This will insert <resource-file src="myfile.txt">
to the exported config.xml.
More information about how resource files are used in Cordova can be found in the Cordova documentation.
The options object uses the following properties.
- src
- The
src
attribute of the resource-file
tag. Location of the file relative to config.xml.
- target Optional
- The
target
attribute of the resource-file
tag. Path to where the file will be copied.
- platform Optional
- Specify a specific platform the Cordova plugin applies to. By default this is
"all"
meaning it will be used in both Android and iOS exports. However it can be set to "android"
or "ios"
to only be included when exporting to a specific platform.
Remote script dependencies
Plugins and behaviors may also specify remote script dependencies. These are loaded from a cross-origin URL, e.g. https://example.com/api.js
.
Use AddRemoteScriptDependency
to add a remote URL to load a script from. The second parameter can optionally be set to "module"
to load the script as a module. For example:
// Load remote "classic" script
this._info.AddRemoteScriptDependency("https://example.com/api.js");
// Load remote module script
this._info.AddRemoteScriptDependency("https://example.com/api-module.js", "module");
This will produce the following tags on export, loaded before the runtime:
<!-- Classic script -->
<script src="https://example.com/api.js"></script>
<!-- Module script -->
<script src="https://example.com/api-module.js" type="module"></script>