背景:我在项目文件夹中通过 linux 上的 npm 安装了一个 cordova 3.0.9(根据 package.json)项目。
命令历史如下(在Cordova的npm安装之后,安装android SDK等,并创建项目文件夹):
cordova create . com.myproject MyProject
(很好,我得到了一个包含 config.xml 的 www 目录,以及虚拟的 hello cordova 应用程序等。这个 config.xml 具有我的项目的正确名称等,默认情况下在其中生成)
cordova platform add android
(我得到了 platforms/android 文件夹等)
现在我安装一些插件
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation.git
这很好,但也是事情变得有趣的地方。我注意到插件安装以及将 src 添加到插件目录也会更新我的 platforms/android/res/xml/config.xml,其中包含适用于 Android 的有用指令,例如:
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.CompassListener" />
</feature>
重要的是要注意,我知道我的 www 目录中的 config.xml 是执行“cordova build”所必需的,但它永远不会更新与我安装的插件相关的任何信息,我什至有点担心/尤其是阅读之后:
http://docs.phonegap.com/en/3.0.0/config_ref_index.md.html#Configuration%20Reference .
我可以在这里回答我自己的问题,但还有一些问题/疑虑。
因此,从逻辑上讲,www 目录中的 config.xml 仍然是非平台特定的,仍然乏味且无趣,并且仅包含平台独立指令。但是我对此很好奇,因为独立于平台的人肯定仍然应该了解插件吗?也是平台特定的(platforms/android/res/xml/config.xml),甚至不知道我的项目的名称,它仍然被称为“Hello Cordova”。这也有点令人担忧。
所以有人可以告诉我是否一切正常吗?具体来说:
- 我的平台独立 config.xml 是否需要了解我安装的插件? (cli 没有执行此操作是错误/TODO 吗?)
- 我的平台特定 config.xml 是否需要知道我的项目/应用程序的正确名称? (这里又是一个错误/待办事项?)
- 如果前两个不是错误,cordova 构建过程是否会在某个阶段引入每个平台特定的 config.xml,覆盖或合并平台无关的 config.xml?
- 我还应该注意两者之间的其他区别吗?
- 最终,我是否需要在执行“cordova 构建”之前手动更新 www/config.xml(以及特定于平台的文件),因为 CLI 没有尽其所能/应该?
提前致谢。
最佳答案
Cordova CLI github 页面上的 README.md,https://github.com/apache/cordova-cli ,有更多的信息。
www/config.xml
文件是您的主要配置文件。每当您执行 cordova build
或类似操作时都会使用它。但并非其中的所有属性实际上都很重要。例如不是插件。
来自 README.md
cordova-cli supports changing your application's data via the following elements inside the config.xml file:
- The user-facing name can be modified via the contents of the element.
- The package name (AKA bundle identifier or application id) can be modified via the id attribute from the top-level element.
- The version can be modified via the version attribute from the top-level element.
- The whitelist can be modified using the elements. Make sure the origin attribute of your element points to a valid URL (you can use * as wildcard). For more information on the whitelisting syntax, see the docs.phonegap.com. You can use either attribute uri (BlackBerry-proprietary) or origin (standards-compliant) to denote the domain.
- Platform-specific preferences can be customized via tags. See docs.phonegap.com for a list of preferences you can use.
- The entry/start page for your application can be defined via the element + attribute.
我猜这应该意味着以下内容:
- 没有
- 不,它会在构建阶段被覆盖。
- 是的,如果使用特定于平台的功能,还会涉及其他文件,例如 AndroidManifest.xml。
- 据我所知没有。
- 如果您在不使用 cordova cli 的情况下添加插件,即第三方插件,则需要更新它。
关于android - 为什么我的 config.xml 文件似乎没有被 Cordova 3.0.9 CLI 正确更新,我应该自己手动更新它们吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18730475/