Config.xml can be defined as a global configuration file of the Cordova application, where we can change the configuration of our app. In the previous section, we have created our first Cordova application, where we set reverse domain and name. If you want to change these existing values, you can easily change them by using the config.xml file.
It is a platform-agnostic xml file that consists of all the necessary information required by the Cordova to convert the code in the www folder to the platform-specific installer. This file controls the Cordova behavior based on the W3C's packaged web apps. It also specifies the metadata of the application. It is a default file that is automatically created when creating any Cordova app.
This file can be edited either manually or using specific commands of Command Line Interface (CLI). We can add two configurations to this file, i.e., global and platform-specific.
The global configuration specifies the configuration that is common to all the devices, whereas the platform-specific configuration is specific to the platform.
The configurations are parsed to an app, and then the content is translated into a set of features. These features are responsible for generating the policy to access the native device APIs and show the app interaction with the web domains.
This file is available at the top-level directory of an app:
Before version 3.3.1- 0.2.0, the config.xml file was present at app/www/config.xml.
When we build any app using the CLI, versions of the config.xml file are copied into various platforms/ subdirectories.
Configuration table of config.xml file:
The below table defines the elements used in the config.xml file:
The widget is the root element of the config.xml file. The widgets-config.xml file stores the information of widget definitions, widget attributes, page definitions, and default widget templates. We can edit the configuration settings of config.xml to perform several tasks. For example, if we want to enable the custom widgets, we can easily do that by defining the widget in the config.xml file. It consists of some attributes that are listed below:
preference: An element that is used to set various options as pairs of name/value attributes. The name of the preference is case-insensitive. Many preferences are specific to individual platforms. Some of the attributes of preference are listed below:
If you want to use CLI to build an app, you must have to use the plugin commands to enable device APIs. Thus, the top-level config.xml file does not vary. Thereby, the element is not applied to the workflow. If you work directly in an SDK and use a source file of platform-specific config.xml, you must have to use the tag to enable device-level APIs and the external plugins.
Name: An attribute of a feature of string type that defines the name of the plugin to enable.