Config.xml API
The config.xml
file is a global configuration file that manages various aspects of a Cordova application's behavior. It is written in XML format and follows the structure outlined in the W3C's Packaged Web Apps (Widgets) specification. Additionally, it is extended to include core Cordova API features, plugins, and platform-specific settings.
If you are using the Cordova CLI to create your project (as explained in The Command-Line Interface), you can locate the config.xml
file in the top-level directory of your project.
./hellocordova
└── config.xml
When using the CLI to build a project, versions of this file are passively copied into various platforms/
subdirectories. For example:
./hellocordova
└── platforms
├── android
│ └── app
│ └── src
│ └── main
│ └── res
│ └── xml
│ └── config.xml
└── ios
└── HelloCordova
└── config.xml
Some platforms offer integrated development environments (IDEs) like Xcode for iOS and Android Studio for Android, which allow you to build and test your application. If you choose to use these IDEs for building and testing your project, it is recommended to run the cordova prepare
CLI command whenever you make changes to the Cordova application's config.xml
. This ensures that the updated configurations are copied into the respective platforms/
subdirectories.
In addition to the configuration options described below, you have the ability to customize the core set of images for your application on each target platform. For more information, please refer to the topic on Customizing Icons.
Sample config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
id="io.cordova.hellocordova"
version="1.0.0">
<name>HelloCordova</name>
<description>Sample Apache Cordova App</description>
<author email="dev@cordova.apache.org" href="https://cordova.apache.org">
Apache Cordova Team
</author>
<content src="index.html" />
<!-- Security Related Settings -->
<access origin="https://cordova.apache.org" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<!-- Platform Configs & Platform Overriding Configs -->
<platform name="android"></platform>
<platform name="ios"></platform>
</widget>
widget
Root element of the config.xml document.
Attributes | Description |
---|---|
id String |
Required Specifies the app's identifier. The id should be in a reverse-DNS format however, only alphanumeric and dot characters are allowed. e.g: com.example.myapp |
version String |
Required Full version number expressed in major/minor/patch notation. |
android-versionCode String |
Alternative version for Android. Sets the version code for the application. See the Android guide for information on how this attribute may be modified. |
ios-CFBundleVersion String |
Alternative version for iOS. For further details, see Apple Developer - CFBundleVersion. |
android-packageName String |
This preference overrides the id attribute with an alternative package name specifically for Android. |
ios-CFBundleIdentifier String |
This preference overrides the id attribute with an alternative bundle ID specifically for iOS. |
defaultlocale String |
Specify the default language of the app using an IANA language code. This preference key explicitly sets the value for CFBundleDevelopmentRegion. For example, you can use values like en or en_US . |
android-activityName String |
Set the activity name for your app in AndroidManifest.xml. Note that this is only set once after the Android platform is first added. |
xmlns String |
Required Namespace for the config.xml document. |
xmlns:cdv String |
Required Namespace prefix. |
Examples:
<!-- Android -->
<widget id="io.cordova.hellocordova" version="0.0.1" android-versionCode="13" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>
<!-- iOS -->
<widget id="io.cordova.hellocordova" version="0.0.1" ios-CFBundleVersion="0.1.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
</widget>
name
Specifies the app's formal name, as it appears on the device's home screen and within app-store interfaces.
Examples:
<widget ...>
<name>HelloCordova</name>
</widget>
short name
Specifies an optional display name for the app. Sometimes the app name should be displayed differently on device's home screen than on informational and app-store interfaces due to limited space.
Examples:
<widget ...>
<name short="HiCdv">HelloCordova</name>
</widget>
description
Specifies metadata that may appear within app-store listings.
Examples:
<widget ...>
<description>A sample Apache Cordova application</description>
</widget>
author
Specifies contact information that may appear within app-store listings.
Attributes | Description |
---|---|
email String |
Required Email of the author. |
href String |
Required Website of the author. |
Examples:
<widget ...>
<author email="dev@cordova.apache.org" href="https://cordova.io"></author>
</widget>
content
Defines the app's starting page in the top-level web assets directory. The default value is index.html, which customarily appears in a project's top-level www
directory.
Attributes | Description |
---|---|
src String |
Required Defines the app's starting page in the top-level web assets directory. The default value is index.html, which customarily appears in a project's top-level www directory. |
Examples:
<widget ...>
<content src="startPage.html"></content>
</widget>
access
Defines the external domains that the app is allowed to communicate with. When the access origin is set to "*", the app can access any server, but this can potentially create a security risk. It is recommended to explicitly specify the permitted URLs to ensure a secure configuration. For detailed instructions, please refer to the Allow List Guide.
Attributes | Description |
---|---|
origin String |
Required Defines the external domain URL or URL pattern that the app is allowed to communicate with. |
Examples:
<widget ...>
<access origin="*"></access>
</widget>
<widget ...>
<access origin="http://google.com"></access>
</widget>
allow-navigation
Controls which URLs the WebView can be navigated to. Applies to top-level navigations only. See the Allow List Guide for details.
Attributes | Description |
---|---|
href String |
Required Defines the external domain or domain pattern that the WebView is allowed to navigate to. |
Examples:
<!-- Allow links to example.com -->
<allow-navigation href="http://example.com/*" />
<!-- Wildcards are allowed for the protocol, as a prefix to the host, or as a suffix to the path -->
<allow-navigation href="*://*.example.com/*" />
allow-intent
Controls which URLs the app is allowed to ask the system to open. By default, no external URLs are allowed. See the Allow List Guide for details.
Attributes | Description |
---|---|
href String |
Required Defines the URL or URL pattern that the app is allowed to ask the system to open. |
Examples:
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
edit-config
See <config-file> docs for plugin.xml.
config-file
See <config-file> docs for plugin.xml.
engine
Specifies details about what platform to restore during a prepare.
Attributes | Description |
---|---|
name String |
Required Name of the platform to be restored |
spec String |
Required Details about the platform to be restored. This could be a major.minor.patch version number, a directory containing the platform or a url pointing to a git repository. This information will be used to retrieve the platform code to restore from NPM, a local directory or a git repository. See Platform Spec for further details. |
Examples:
<engine name="android" spec="https://github.com/apache/cordova-android.git#5.1.1" />
<engine name="ios" spec="^4.0.0" />
plugin
Specifies details about what plugin to restore during a prepare. This element
is automatically added to a project's config.xml
when a plugin is added using
the --save
flag. See the CLI reference for more information on
adding plugins.
Note: As of Cordova 9.x, this tag is obsolete. Learn More
Attributes | Description |
---|---|
name String |
Required Name of the plugin to be restored |
spec String |
Required Details about the plugin to be restored. This could be a major.minor.patch version number, a directory containing the plugin or a url pointing to a git repository. This information will be used to retrieve the plugin code to restore from NPM, a local directory or a git repository. See Plugin Spec for further details. |
Examples:
<plugin name="cordova-plugin-device" spec="^1.1.0" />
<plugin name="cordova-plugin-device" spec="https://github.com/apache/cordova-plugin-device.git#1.0.0" />
variable
Persists the value of a CLI variable to be used when restoring a plugin during a
prepare. This element is added to config.xml
when a plugin that uses CLI variables
is added using the --save
flag. See the CLI reference for more
information on adding plugins.
Note that this value is only used when the plugin is restored to the project during a
prepare, changing it will not change the value used by the plugin in the current
project. In order for changes to this value to take effect, remove the plugin from the
project and restore it by running cordova prepare
. See the
preference element of plugin.xml
for more details on CLI variables.
Attributes | Description |
---|---|
name String |
Required Name of the CLI variable. Can only contain capital letters, digits, and underscores. |
value String |
Required Value of the CLI variable to be used when restoring the parent plugin during a prepare. |
Examples:
<plugin name="cordova-plugin-device" spec="^1.1.0">
<variable name="MY_VARIABLE" value="my_variable_value" />
</plugin>
preference
Sets various options as pairs of name/value attributes. Each preference's name is case-insensitive. Many preferences are unique to specific platforms, and will be indicated as such.
Attributes | Description |
---|---|
AllowInlineMediaPlayback Boolean |
Default: false Set to true to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the playsinline attribute to any <video> elements. NOTE: Prior to iOS 10, <video> elements need to use the webkit-playsinline attribute name instead. |
AllowNewWindows Boolean |
Default: false Set to true to allow JavaScript window.open and HTML target="_blank" links to open a new view overlaying the web view. |
AndroidLaunchMode String |
Default: singleTop Allowed values: standard, singleTop, singleTask, singleInstance Sets the Activity android:launchMode attribute. This changes what happens when the app is launched from app icon or intent and is already running. |
AndroidInsecureFileModeEnabled Boolean |
Default: false If set to true loading file:/// URLs is allowed. Note: Enabling this setting allows malicious scripts loaded in a file:/// context to launch cross-site scripting attacks, either accessing arbitrary local files including WebView cookies, app private data or even credentials used on arbitrary web sites. |
android-maxSdkVersion Number |
Default: Not Specified Sets the maxSdkVersion attribute of the <uses-sdk> tag in the project's AndroidManifest.xml (see here). |
android-minSdkVersion Number |
Default: Dependent on cordova-android Version Sets the minSdkVersion attribute of the <uses-sdk> tag in the project's AndroidManifest.xml (see here). |
android-targetSdkVersion Number |
Default: Dependent on cordova-android Version Sets the targetSdkVersion attribute of the <uses-sdk> tag in the project's AndroidManifest.xml (see here). |
android-compileSdkVersion Number |
Default: Dependent on cordova-android Version Sets the compileSdkVersion attribute. |
android-buildToolsVersion Semver |
Default: Dependent on cordova-android Version Expects a full version string eg. "32.0.0". Changing this may also requires changing the PATH environment variable to find the proper build tools. This preference is primarily for cordova development, for testing upcoming versions of the Android SDK. Changing this has a high risk of breaking builds as newer build tools frequently introduce breaking changes. |
GradleVersion String |
Default: Dependent on cordova-android Version Sets the gradle wrapper version to use. This preference is primarily for cordova development, for testing upcoming versions of the Android SDK. Changing this has a high risk of breaking builds as newer build tools frequently introduce breaking changes. |
AndroidGradlePluginVersion Semver |
Default: Dependent on cordova-android Version Sets the Android Gradle Plugin version to use. This preference is primarily for cordova development, for testing upcoming versions of the Android SDK. Changing this has a high risk of breaking builds as newer build tools frequently introduce breaking changes. |
AndroidXAppCompatVersion Semver |
Default: Dependent on cordova-android Version Overrides Android App Compat library version. |
AndroidXWebKitVersion Semver |
Default: Dependent on cordova-android Version Overrides Android WebKit library version. |
AppendUserAgent String |
If set, the value will append to the end of old UserAgent of webview. When using with OverrideUserAgent, this value will be ignored. |
BackgroundColor String |
Sets the app's background color. Supports a four-byte hex value, with the first byte representing the alpha channel, and standard RGB values for the following three bytes. Note: transparent value will set the application tile background to the accent color on Windows. |
CordovaWebViewEngine String |
Default: CDVWebViewEngine This sets the WebView engine plugin to be used to render the host app. The plugin must conform to the CDVWebViewEngineProtocol protocol. The 'value' here should match the 'feature' name of the WebView engine plugin that is installed. This preference usually would be set by the WebView engine plugin that is installed, automatically. |
DefaultVolumeStream String |
Default: default Added in cordova-android 3.7.0, This preference sets which volume the hardware volume buttons link to. By default this is "call" for phones and "media" for tablets. Set this to "media" to have your app's volume buttons always change the media volume. Note that when using Cordova's media plugin, the volume buttons will dynamically change to controlling the media volume when any Media objects are active. |
DisallowOverscroll Boolean |
Default: false Set to true if you don't want the interface to display any feedback when users scroll past the beginning or end of content. On iOS, overscroll gestures cause content to bounce back to its original position. on Android, they produce a more subtle glowing effect along the top or bottom edge of the content. |
EnableViewportScale Boolean |
Default: false Set to true to allow a viewport meta tag to either disable or restrict the range of user scaling, which is enabled by default. Place a viewport such as the following in the HTML to disable scaling and fit content flexibly within the rendering WebView: <meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no' /> |
ErrorUrl Url |
Default: null When this preference is set, the application will display the specified local page upon encountering an error. Additionally, if this preference is set, the Android system will suppress the default dialog titled "Application Error". |
FullScreen Boolean |
Default: false Allows you to hide the status bar at the top of the screen. Note: Recommended platform-agnostic way to achieve this is to use the StatusBar plugin. |
GapBetweenPages Float |
Default: 0 The size of the gap, in points, between pages. |
GradlePluginGoogleServicesEnabled Boolean |
Default: false Set to true to enable the Google Services Gradle plugin. |
GradlePluginGoogleServicesVersion Semver |
Default: Dependent on cordova-android Version Overrides the Google Services library version. |
GradlePluginKotlinEnabled Boolean |
Default: false Set to true to allow Kotlin files to be built. |
GradlePluginKotlinCodeStyle String |
Default: official Allowed values: official, obsolete Sets how the Kotlin code is formatting for readability. |
GradlePluginKotlinVersion Semver |
Default: 1.3.50 Set the version of the Kotlin Gradle plugin to be used. |
InAppBrowserStorageEnabled Boolean |
Default: true Controls whether pages opened within an InAppBrowser can access the same localStorage and WebSQL storage as pages opened with the default browser. |
InspectableWebview Boolean |
Default: depends on Debug/Release build On iOS 16.4 or later, enables or disables the webview inspector. Defaults to true on debug builds and false on release builds. This preference is ignored on iOS 16.3 and earlier; the inspector is always enabled on debug builds and always disabled on release builds. |
KeepRunning Boolean |
Default: true Determines whether the application stays running in the background even after a pause event fires. Setting this to false does not kill the app after a pause event, but simply halts execution of code within the cordova webview while the app is in the background. |
KeyboardDisplayRequiresUserAction Boolean |
Default: true Set to false to allow the keyboard to appear when calling focus() on form inputs. |
LoadUrlTimeoutValue Number |
Default: 20000, 20 seconds When loading a page, the amount of time in miliseconds to wait before throwing a timeout error. |
LoadingDialog String |
Default: null If set, displays a dialog with the specified title and message, and a spinner, when loading the first page of an application. The title and message are separated by a comma in this value string, and that comma is removed before the dialog is displayed. |
LogLevel String |
Default: DEBUG Allowed values: ERROR, WARN, INFO, DEBUG, VERBOSE Sets the minimum log level through which log messages from your application will be filtered. |
MediaPlaybackAllowsAirPlay Boolean |
Default: true Set to false to prevent Air Play from being used in this view. Available in default UIWebView and WKWebView. |
MediaPlaybackRequiresUserAction Boolean |
Default: false Set to true to prevent HTML5 videos or audios from playing automatically with the autoplay attribute or via JavaScript. |
Orientation String |
Default: default Allowed values: default, landscape, portrait Allows you to lock orientation and prevent the interface from rotating in response to changes in orientation. NOTE: The default value means Cordova will strip the orientation preference entry from the platform's manifest/configuration file allowing the platform to fallback to its default behavior. For iOS, to specify both portrait & landscape mode you would use the platform specific value 'all'. |
OverrideUserAgent String |
If set, the value will replace the old UserAgent of webview. It is helpful to identify the request from app/browser when requesting remote pages. Use with caution, this may cause compatibility issues with web servers. For most cases, use AppendUserAgent instead. |
PageLength Float |
Default: 0 The size of each page, in points, in the direction that the pages flow. When PaginationMode is right to left or left to right, this property represents the width of each page. When PaginationMode is topToBottom or bottomToTop, this property represents the height of each page. The default value is 0, which means the layout uses the size of the viewport to determine the dimensions of the page. |
PaginationBreakingMode String |
Default: page Allowed values: page, column Valid values are page and column.The manner in which column- or page-breaking occurs. This property determines whether certain CSS properties regarding column- and page-breaking are honored or ignored. When this property is set to column, the content respects the CSS properties related to column-breaking in place of page-breaking. |
PaginationMode String |
Default: unpaginated Allowed values: unpaginated, leftToRight, topToBottom, bottomToTop, rightToLeft This property determines whether content in the web view is broken up into pages that fill the view one screen at a time,or shown as one long scrolling view. If set to a paginated form, this property toggles a paginated layout on the content, causing the web view to use the values of PageLength and GapBetweenPages to relayout its content. |
PreferredContentMode String |
Default: auto Sets the content mode (user agent) for the WebView and InAppBrowsers WebView on iPads. Valid values are: mobile and desktop . |
InAppBrowserStatusBarStyle String |
Default: default Set text color style of the StatusBar for InAppBrowser for iOS. Valid values are: lightcontent and default . |
SetFullscreen Boolean |
Default: false Same as the Fullscreen parameter in the global configuration of this xml file. This Android-specific element is deprecated in favor of the global Fullscreen element, and will be removed in a future version. |
ShowTitle Boolean |
Default: false Show the title at the top of the screen. |
Suppresses3DTouchGesture Boolean |
Default: false Set to true to avoid 3D Touch capable iOS devices rendering a magnifying glass widget when the user applies force while longpressing the webview. Test your app thoroughly since this disables onclick handlers, but plays nice with ontouchend. If this setting is true, SuppressesLongPressGesture will effectively be true as well. |
SuppressesIncrementalRendering Boolean |
Default: false Set to true to wait until all content has been received before it renders to the screen. |
SuppressesLongPressGesture Boolean |
Default: false Set to true to avoid iOS9+ rendering a magnifying glass widget when the user longpresses the webview. Test your app thoroughly since this may interfere with text selection capabilities. |
SwiftVersion String |
Default: (empty) Set to specify the Swift Version. |
TopActivityIndicator String |
Default: gray Allowed values: whiteLarge, white, gray. Controls the appearance of the small spinning icon in the status bar that indicates significant processor activity. |
UIWebViewDecelerationSpeed String |
Default: normal Allowed values: normal, fast This property controls the deceleration speed of momentum scrolling. normal is the default speed for most native apps, and fast is the default for Mobile Safari. |
deployment-target String |
This sets the IPHONEOS_DEPLOYMENT_TARGET in the build, which ultimately translates to the MinimumOSVersion in the ipa. For more details please refer to Apple's documentation on Deployment Target Settings |
target-device String |
Default: universal Allowed values: handset, tablet, universal This property maps directly to TARGETED_DEVICE_FAMILY in the xcode project. Note that if you target universal (which is the default) you will need to supply screen shots for both iPhone and iPad or your app may be rejected. |
scheme String |
Default: - Android: https - iOS: not defined, but falls back to app if the value is invalid.Allowed values: - Android: http or https - iOS: Any non-reserved schemes. (Example Reserved Schemes) This property contains the scheme which your app content is served from. |
hostname String |
Default: localhost This property contains the hostname which the app content is served from. If the preference scheme is not defined for iOS, the hostname value will be ignored. |
Examples:
<preference name="DisallowOverscroll" value="true"/>
<preference name="Fullscreen" value="true" />
<preference name="BackgroundColor" value="0xff0000ff"/>
<preference name="HideKeyboardFormAccessoryBar" value="true"/>
<preference name="Orientation" value="landscape" />
<!-- iOS only preferences -->
<preference name="EnableViewportScale" value="true"/>
<preference name="MediaPlaybackAllowsAirPlay" value="false"/>
<preference name="MediaPlaybackRequiresUserAction" value="true"/>
<preference name="AllowInlineMediaPlayback" value="true"/>
<preference name="TopActivityIndicator" value="white"/>
<preference name="SuppressesIncrementalRendering" value="true"/>
<preference name="GapBetweenPages" value="0"/>
<preference name="PageLength" value="0"/>
<preference name="PaginationBreakingMode" value="page"/>
<preference name="PaginationMode" value="unpaginated"/>
<preference name="UIWebViewDecelerationSpeed" value="fast" />
<preference name="ErrorUrl" value="myErrorPage.html"/>
<preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" />
<preference name="AppendUserAgent" value="My Browser" />
<preference name="target-device" value="universal" />
<preference name="deployment-target" value="7.0" />
<preference name="CordovaWebViewEngine" value="CDVWebViewEngine" />
<preference name="CordovaDefaultWebViewEngine" value="CDVWebViewEngine" />
<preference name="SuppressesLongPressGesture" value="true" />
<preference name="Suppresses3DTouchGesture" value="true" />
<!-- Android only preferences -->
<preference name="KeepRunning" value="false"/>
<preference name="LoadUrlTimeoutValue" value="10000"/>
<preference name="InAppBrowserStorageEnabled" value="true"/>
<preference name="LoadingDialog" value="My Title,My Message"/>
<preference name="ErrorUrl" value="myErrorPage.html"/>
<preference name="ShowTitle" value="true"/>
<preference name="LogLevel" value="VERBOSE"/>
<preference name="AndroidLaunchMode" value="singleTop"/>
<preference name="AndroidInsecureFileModeEnabled" value="true" />
<preference name="DefaultVolumeStream" value="call" />
<preference name="OverrideUserAgent" value="Mozilla/5.0 My Browser" />
<preference name="AppendUserAgent" value="My Browser" />
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
<preference name="GradlePluginGoogleServicesVersion" value="4.2.0" />
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinCodeStyle" value="official" />
<preference name="GradlePluginKotlinVersion" value="1.3.50" />
feature
If you use the CLI to build applications, you use the plugin command to enable device APIs. This does not modify the top-level config.xml file, so the
Attributes | Description |
---|---|
name String |
Required The name of the plugin to enable. |
param
Used to specify certain plugin parameters such as: what package to retrieve the plugin code from, and whether the plugin code is to be initialized during the Webview's initialization.
Attributes | Description |
---|---|
name String |
Required Allowed values: android-package, ios-package, onload. 'ios-package' and 'android-package' are used to specify the name of the package (as specified by the 'value' attribute) to be used to initialize the plugin code, while 'onload' is used to specify whether the corresponding plugin (as specified in the 'value' attribute) is to be instantiated when the controller is initialized. |
value String/boolean |
Required Specifies the name of the package to be used to initialize the plugin code (when the 'name' attribute is android-package or ios-package), specifies the name of the plugin to be loaded during controller initialization (when 'name' attribute is set to 'onload'). |
Examples:
<!-- Here is how to specify the Device API for Android projects -->
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<!-- Here's how the element appears for iOS projects -->
<feature name="Device">
<param name="ios-package" value="CDVDevice" />
<param name="onload" value="true" />
</feature>
platform
When using the CLI to build applications, it is sometimes necessary to specify preferences or other elements specific to a particular platform. Use the
Attributes | Description |
---|---|
name String |
Required The platform whose preferences are being defined. |
Examples:
<platform name="android">
<preference name="Fullscreen" value="true" />
</platform>
hook
Represents your custom script which will be called by Cordova when certain action occurs (for example, after plugin is added or platform prepare logic is invoked). This is useful when you need to extend default Cordova functionality. See Hooks Guide for more information.
Attributes | Description |
---|---|
type String |
Required Specifies the action during which the custom script is to be called. |
src String |
Required Specifies the location of the script to be called when a specific action occurs. |
Examples:
<hook type="after_plugin_install" src="scripts/afterPluginInstall.js" />
resource-file
This tag installs resource files into your platform, and is similar to the same tag in plugin.xml. This tag is currently only supported on cordova-ios@4.4.0
or greater and cordova-android@6.2.1
or greater.
Attributes | Description |
---|---|
src String |
Required Location of the file relative to config.xml . |
target String |
Path to where the file will be copied in your directory. |
Examples:
For Android:
<resource-file src="FooPluginStrings.xml" target="res/values/FooPluginStrings.xml" />