一、概述
在写这篇文章时,cordova的版本已是9.0.0 。config.xml 是Cordova项目的全局配置文件。 这份配置文件的基础是W3C’s Packaged Web Apps (Widgets) 规范,并进行了扩展。它份配置文件是用来指定核心Cordova API 特性、插件、特定平台的设置等。
Config.xml文件位于用Cordova命令创建的项目的根目录下。如果你用以下命令创建项目:
那么config.xml就在~/Desktop/Cordova/sample/config.xml下。
当使用Cordova命令行创建项目时,这个文件会被复制到platforms/下的子目录下,如:/home/kyun/Desktop/Cordova/sample/platforms/android/app/src/main/res/xml/config.xml
二、config.xml中的标签
我们只挑一些重要的与Android相斗的标签和属性来介绍
widget标签
如果在Android平台上运行的,不要忘了添加Android的命名空间:
属性 | 描述 |
id(string) | 必要的,在Android就是包名,一般是反向写的域名 |
version(string) | 必要的,完整版本号,版本号一般这样组成会较有意义:以主/次/补丁符号表示,如1.1.3表示当前版本是主版本1,次版本为1的第三个3补丁包 |
xmlns(string) | 必要的, config.xml文档的命名空间。 |
xmlns:cdv(string) | 必要的,命名空间前缀 |
android-versionCode(string) | Android的替代版本 |
android-packageName(string) | android的替代包名,覆盖id。 一般不用。 |
android-activityName(string) | |
defaultlocale | 指定应用程序的默认语言,作为IANA语言代码。 |
name标签
指定应用程序的正式名称,该名称显示在设备的主屏幕
content标签
定义app的顶层web assets目录的起始页,默认值是index.html,它通常出现在项目的顶级www目录中。
access标签
定义允许应用程序与之通信的外部域集。
allow-intent标签
定义允许应用程序请求系统打开的URL。
allow-navigation标签
定义允许WebView导航到的外部域集。
platform标签
定义指定平台的首选项。
resource-file标签
属性 | 描述 |
src(string) | 文件相对于config.xml的位置 |
target(string) | 将文件复制到目录中的路径 |
将资源文件安装到平台中
hook标签
属性 | 描述 |
type(string) | 指定调用自定义脚本的操作。 |
src(string) | 指定发生特定操作时要调用的脚本的位置 |
表示当发生某些操作(例如,在添加插件或调用平台准备逻辑之后)时Cordova将调用的自定义脚本。
preference标签
将各种选项设置为名称/值属性对。每个首选项的名称都不区分大小写。许多偏好是特定平台所独有的,并将以这样的方式表示。
属性 | 描述 |
Orientation(string) | 允许值:default, landscape(横向值), portrait(纵向值)。允许您锁定方向并防止界面根据方向的更改而旋转,注意:默认值意味着cordova将从平台的manifest/configuration文件中删除orientation首选项条目,允许平台返回到其默认行为。 |
LoadUrlTimeoutValue(number in milliseconds) | 默认值:20000,20秒。加载页时,引发超时错误之前等待的时间量。 |
KeepRunning(boolean) | 默认值:true。确定应用程序是否在暂停事件激发后仍在后台运行。将此设置为false不会在暂停事件后终止应用程序,而只是在应用程序处于后台时停止在Cordova WebView中执行代码。 |
InAppBrowserStorageEnabled (boolean) | 默认值:true。控制在InAppBrowser中打开的页是否可以访问与使用默认浏览器打开的页相同的本地存储和WebSQL存储 |
FullScreen(boolean) | 默认值:false。允许您隐藏屏幕顶部的状态栏。注意:建议使用statusbar插件来实现这一点。 |
ErrorUrl(URL) | 默认值:null。如果设置,将在应用程序出错时显示引用页,而不是显示标题为“应用程序错误”的对话框。 |
BackgroundColor(string) | 设置应用程序的背景色。 |
AppendUserAgent(string) | 如果设置,该值将追加到webview的旧useragent的末尾。与OverrideUserAgent一起使用时,将忽略此值。 |
android-targetSdkVersion(integer) | 默认:依赖于Cordova Android版本。在项目的androidmanifest.xml中设置标记的targetsdkversion属性 |
AndroidLaunchMode(string) | 默认值:singletop。允许值:standard、singletop、singletask、singleinstance。设置活动android:launchmode属性。这将更改从app icon或intent启动应用程序并已在运行时发生的情况。 |
plugin标签
指定准备期间要还原的插件的详细信息。使用–save标志添加插件时,此元素会自动添加到项目的config.xml中。
属性 | 描述 |
name(string) | 要还原的插件的名称 |
spec(string) | 有关要还原的插件的详细信息。这可能是major.minor.patch版本号、包含插件的目录或指向git存储库的url。此信息将用于从npm、本地目录或git存储库检索要还原的插件代码。 |
engine标签
指定准备期间要还原的平台的详细信息。
属性 | 描述 |
name(string) | 要还原的平台的名称 |
spec(string) | 有关要还原的平台的详细信息。这可能是major.minor.patch版本号、包含平台的目录或指向git存储库的url。此信息将用于从npm、本地目录或git存储库检索要还原的平台代码。 |
上面就是与Android平台比较密切相关的配置信息。
谢谢阅读。