应该在config.xml文件中声明一个phonegap插件吗?

时间:2023-01-13 07:29:28

I am a newbie in phonegap development so I have a couple of questions:

我是phonegap开发的新手,所以我有几个问题:

1) I am using the accelerometer plug-in. I read in the manual that i need to declare the plugin in the config.xml file in order to use it. However I noticed that even if i remove the declaration from the config.xml

1)我正在使用加速度计插件。我在手册中读到我需要在config.xml文件中声明插件才能使用它。但是我注意到即使我从config.xml中删除了声明

<feature name="Accelerometer">
    <param name="android-package" value="org.apache.cordova.AccelListener" />
</feature>

the accelerometer still works.

加速度计仍然有效。

So I would like to ask you if in the phonegap 3.0.0 version , the use of the config.xml is obsolete. If that s the case then where is the binding takes place?

所以我想问你,如果在phonegap 3.0.0版本中,config.xml的使用已经过时了。如果是这种情况那么绑定发生在哪里?

2) I use the android platform to build the app. In the project structure there are three config.xml files with different content:

2)我使用android平台构建应用程序。在项目结构中,有三个具有不同内容的config.xml文件:

  • a) In the assets/www/phonegap-app-hello-world-3.0.0/www/config.xml
  • a)在assets / www / phonegap-app-hello-world-3.0.0 / www / config.xml中
  • b) In the assets/www/phonegap-app-hello-world-3.0.0/config.xml
  • b)在assets / www / phonegap-app-hello-world-3.0.0 / config.xml中
  • c) In the res/xml/config.xml
  • c)在res / xml / config.xml中

What s the use of each one of them ? Where I suppose to declare my plug in? I did it in the res/xml/config/xml file

他们每个人的用处是什么?在哪里我想申报我的插件?我在res / xml / config / xml文件中完成了它

Thank you

谢谢

5 个解决方案

#1


124  

I'm pretty sure the reason that you can still use the plugin is because you either edited the wrong config.xml or did not run the cordova command line tools to propagate your changes to the correct config.xml file that is actually used by the app.

我很确定您仍然可以使用该插件的原因是您编辑了错误的config.xml或者没有运行cordova命令行工具将您的更改传播到实际使用的正确config.xml文件应用程序。

There are multiple config.xml files in different spots in a Cordova 3.x project. I'll try to give you an overview of the different locations of the files and how you should interact with them. Keep in mind that this is what happens when you use the CLI (Command Line-interface) - I generated this directory structure by typing:

Cordova 3.x项目中的不同位置有多个config.xml文件。我将尝试概述文件的不同位置以及如何与它们进行交互。请记住,这是使用CLI(命令行界面)时发生的情况 - 我通过键入以下内容生成了此目录结构:

cordova create {MyApp}
cordova platform add android ios
cordova plugin add org.apache.cordova.network-information

Or prior to Cordova 3.1, replace the last line with:

或者在Cordova 3.1之前,将最后一行替换为:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git

If you use just the platform level shell scripts to build the app (the "old" way that we did in Cordova 2.X), you can generally use the same workflow, but will need to Use Plugman to Manage Plugins. (We are in the process of documenting these two different "workflows".)

如果您仅使用平台级shell脚本来构建应用程序(我们在Cordova 2.X中执行的“旧”方式),您通常可以使用相同的工作流程,但需要使用Plugman来管理插件。 (我们正在记录这两个不同的“工作流程”。)

First, when you create an app with cordova create MyApp, it will create an empty project structure like this:

首先,当您使用cordova创建一个创建MyApp的应用程序时,它将创建一个如下所示的空项目结构:

/myApp/
        /www/           # This is where your "cross-platform' files go.
                        # The build tools copy these files over to the correct
                        # asset folder for each platform, like /assets/www/ for
                        # android or just /www/ for iOs. This is where you should
                        # be doing most/all of your work and is what should
                        # probably be version controlled.
        /platforms/
            /android/   # These will only appear after `cordova platform add`
            /ios/       # You should generally not touch these file as they are
                        # recreated quite often, although changes will persist.
        /plugins/
            /android/   # These will only appear after `cordova plugin add`. They
                        # pretty much just contain the native and web plugin code
                        # for all platforms that a plugin supports.
            /ios/
        /merges/        # This is where you can place platform-specific code that
                        # you write that will get merged in with your cross
                        # platform source, see the "customize each platform"
                        # section of: http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html

You should make all of your changes to files in /www/, which is the "cross platform" source code. Whatever is in this folder will generally get copied and propagated to the platform level www folder when you use the command line tools (whether its /assets/www for Android or just /www/ for iOS). This way, you only need a single source folder for your app - this is the folder that you should have under version control. Any app-wide configuration changes that you want should be made to the config.xml file placed at this location; later when you use the tools, this config.xml file will be copied (and sometimes modified with platform-specific configuration information) to the appropriate place for each app, like /platforms/android/res/xml/config.xml (for android) or /platforms/ios/AppName/config.xml (for iOS).

您应该对/ www /中的文件进行所有更改,这是“跨平台”源代码。当您使用命令行工具时(无论是针对Android的/ assets / www还是仅针对iOS的/ www /),此文件夹中的任何内容通常都会被复制并传播到平台级www文件夹。这样,您只需要一个应用程序的单个源文件夹 - 这是您在版本控制下应具有的文件夹。您想要的所有应用程序范围的配置更改都应该放在此位置的config.xml文件中;稍后当您使用这些工具时,此config.xml文件将被复制(有时会使用特定于平台的配置信息进行修改)到每个应用的适当位置,例如/platforms/android/res/xml/config.xml(用于android )或/platforms/ios/AppName/config.xml(适用于iOS)。

Say you want to add the acceleration plugin by typing cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git. If you were to run a diff after this command, you will see the following files have been changed or added:

假设您要通过键入cordova plugin添加https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git来添加加速插件。如果您在此命令后运行diff,您将看到以下文件已被更改或添加:

plugins/org.apache.cordova.network-information/ - This new folder contains all of the plugin meta information and code, including web and native code, for each supported platform

plugins / org.apache.cordova.network-information / - 这个新文件夹包含每个支持平台的所有插件元信息和代码,包括Web和本机代码

plugins/android.json and plugins/ios.json - Both of these files have been edited now to contain a reference to the network-information plugin. This is where you will see the config-munge bit of JSON. As you add more plugins, this file will continuously grow to reference all of them. This file tells the command line tools what code it needs to replace and in which files. For example, after adding the cordova-plugin-network-information plugin, you will see this in /plugins/android.json:

plugins / android.json和plugins / ios.json - 现在已经编辑了这两个文件,以包含对网络信息插件的引用。在这里您将看到JSON的config-munge位。随着您添加更多插件,此文件将不断增长以引用所有插件。该文件告诉命令行工具需要替换的代码和文件。例如,在添加cordova-plugin-network-information插件后,您将在/plugins/android.json中看到:

{
        "prepare_queue": {
            "installed": [],
            "uninstalled": []
        },
        "config_munge": {
            "res/xml/config.xml": {
                "/*": {
                    "<feature name=\"NetworkStatus\"><param name=\"android-package\" value=\"org.apache.cordova.networkinformation.NetworkManager\" /></feature>": 1
                }
            },
            "AndroidManifest.xml": {
                "/*": {
                    "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />": 1
                }
            }
        },
        "installed_plugins": {
            "org.apache.cordova.network-information": {
                "PACKAGE_NAME": "io.cordova.hellocordova"
            }
        },
        "dependent_plugins": {}
    }

This tells the scripts to write the feature name into res/xml/config.xml (again, for iOS, this will be different, since the app level config file is in a different location on iOS!), and also tells it to write android.permission.ACCESS_NETWORK_STATE permission into AndroidManifest.xml (you won't find anything like this on iOS since no permissions are necessary.) (By the way, what gets written to each of these json files is defined in the plugin's plugin.xml file.)

这告诉脚本将功能名称写入res / xml / config.xml(同样,对于iOS,这将是不同的,因为应用程序级别配置文件位于iOS上的不同位置!),并且还告诉它写入android.permission.ACCESS_NETWORK_STATE权限进入AndroidManifest.xml(你不会在iOS上找到这样的东西,因为不需要权限。)(顺便说一句,在插件的plugin.xml中定义了写入每个json文件的内容文件。)

platforms/android/AndroidManifest.xml - The CLI tools took care of adding whichever permission were defined in the plugin's xml file to AndoridManifest. Yes, this happens when you do cordova plugin add. These permissions are directly copied from whatever is in the plugins/android.json file. These permissions are also deleted when you 'rm' a plugin. However, editing these files is done intelligenty, in that you can add custom things to AndroidManifest.xml and they will persist.

platforms / android / AndroidManifest.xml - CLI工具负责将插件的xml文件中定义的任何权限添加到AndoridManifest。是的,当你执行cordova插件添加时会发生这种情况。这些权限直接从plugins / android.json文件中的任何内容复制。当你'插件'时,这些权限也会被删除。但是,编辑这些文件是智能的,因为您可以将自定义内容添加到AndroidManifest.xml,它们将保持不变。

platforms/android/assets/www/cordova_plugins.js - This file is buried inside the html resources that will make up your final app - these resources (pretty much anything in /platforms/) should not be edited by you because they will be replaced by the CLI tools quite frequently. This file is used by Cordova at runtime to load the plugin code that you added; it also takes care of mapping the JavaScript namespaces to the actual files (this is the "clobbers" declaration.) For example, I see:

platforms / android / assets / www / cordova_plugins.js - 这个文件隐藏在构成你最终应用程序的html资源里面 - 这些资源(/ platforms /中的几乎任何东西)都不应该由你编辑,因为它们会被替换通过CLI工具非常频繁。 Cordova在运行时使用此文件来加载您添加的插件代码;它还负责将JavaScript命名空间映射到实际文件(这是“clobbers”声明。)例如,我看到:

{
    "file": "plugins/org.apache.cordova.network-information/www/network.js",
    "id": "org.apache.cordova.network-information.network",
    "clobbers": [
        "navigator.connection",
        "navigator.network.connection"
    ]
}

this means that in your app code, navigator.connection and navigator.network.connection will both map to the code contained in plugins/org.apache.cordova.network-information/www/network.js.

这意味着在您的应用程序代码中,navigator.connection和navigator.network.connection都将映射到plugins / org.apache.cordova.network-information / www / network.js中包含的代码。

platforms/android/res/xml/config.xml - This is the platform-level config.xml file for Android. This file gets created by the CLI tools. A lot of the information that you write in your top level config.xml (/MyApp/www/config.xml) will get copied here, but not all of it (and there is some additional stuff, I'm not exactly sure where the additional stuff comes from.) This is the file that gets read by Android when it is running your app and it needs to check your config data. For example, Cordova Android code will use this to see which plugins are installed and which native classes map to which namespaces. I think the only way you could edit this is by using the /merges/ folder that I mentioned above.

platforms / android / res / xml / config.xml - 这是Android的平台级config.xml文件。此文件由CLI工具创建。您在*config.xml(/MyApp/www/config.xml)中编写的大量信息将在此处复制,但不是全部(并且还有一些其他内容,我不确定在哪里额外的东西来自。)这是Android在运行你的应用程序时读取的文件,它需要检查你的配置数据。例如,Cordova Android代码将使用它来查看安装了哪些插件以及哪些本机类映射到哪些命名空间。我认为你可以编辑的唯一方法是使用我上面提到的/ merges /文件夹。

platforms/ios/{AppName}.xcodeprojcj/project.pbxproj - The iOS equivalent of AndroidManifest.xml

platforms / ios / {AppName} .xcodeprojcj / project.pbxproj - 相当于AndroidManifest.xml的iOS

platforms/ios/{AppName}/config.xml - This is the platform-level config.xml file for iOS. See how it is in a different spot than on Android? (eg, not in /res/xml/config.xml?) This file automatically gets updated by the CLI and you should not touch it.

platforms / ios / {AppName} /config.xml - 这是iOS的平台级config.xml文件。了解它与Android不同的地方? (例如,不在/res/xml/config.xml中?)CLI会自动更新此文件,您不应该触摸它。

platforms/ios/www/cordova_plugins.js - The same file exists on Android (but in a different location) and has the same purpose: to help Cordova load your plugins at run time when somebody is using the app

platforms / ios / www / cordova_plugins.js - Android上存在相同的文件(但位于不同的位置)并且具有相同的目的:当有人使用应用程序时,帮助Cordova在运行时加载插件

I think that pretty much describes all of the files and folders that are used in a cordova project.

我认为这几乎描述了cordova项目中使用的所有文件和文件夹。

Hopefully now you can see that you should in fact only be editing the /www/config.xml file. This file will be used to construct the /platforms/android/res/xml/config.xml and /platforms/ios/{AppName}/config.xml, which are used by Cordova when the packaged app is running. Parts of this file will be used to edit the AndroidManifest.xml and project.pbxprojc files (for Android and iOS, respectively.)

希望现在你可以看到你实际上只应该编辑/www/config.xml文件。此文件将用于构造/platforms/android/res/xml/config.xml和/platforms/ios/{AppName}/config.xml,它们在打包的应用程序运行时由Cordova使用。此文件的一部分将用于编辑AndroidManifest.xml和project.pbxprojc文件(分别用于Android和iOS)。

This explains why you were still able to use the accelerometer in your app even after deleting the <feature name="Accelerometer"> lines - they were just being recopied into the platform level config.xml from the main app wide config.xml

这解释了为什么即使在删除 行之后您仍然可以在应用程序中使用加速度计 - 它们只是从主应用程序范围的config.xml重新复制到平台级别config.xml中

I guess the only thing left to figure out is how you can edit platform specific configuration files; for example, how can you edit the AndroidManifest.xml file? Well, it turns out that you can just edit the /platforms/android/AndroidManifest.xml file directly - the CLI is smart enough to not erase your customizations when it automatically adds or removes plugin permissions. So say for some reason you needed to support a lower version of Android than what Cordova supports, you can just change the object and it will persist though your cordova plugin add|rm {id} calls.

我想唯一要弄清楚的是如何编辑特定于平台的配置文件;例如,如何编辑AndroidManifest.xml文件?好吧,事实证明你可以直接编辑/platforms/android/AndroidManifest.xml文件 - CLI足够聪明,在自动添加或删除插件权限时不会删除自定义。所以说出于某些原因你需要支持比Cordova支持的更低版本的Android,你可以只更改对象,它会持续存在但你的cordova插件添加| rm {id}调用。

I hope that clarifies things, feel free to ask any more questions!

我希望澄清事情,随时提出更多问题!

#2


22  

Since cordova 3.5, we can persist plugins in config.xml file

从cordova 3.5开始,我们可以在config.xml文件中保存插件

<feature name="Network Information">
    <param name="id" value="org.apache.cordova.network-information" />
    <param name="version" value="0.2.10" />
</feature>

The following command will fetch the plugins defined in config.xml

以下命令将获取config.xml中定义的插件

cordova restore plugins --experimental

The following command will write your current installed plugins in config.xml (3.5):

以下命令将在config.xml(3.5)中编写当前安装的插件:

cordova save plugins --experimental

In 5.x and later:

在5.x及更高版本中:

cordova plugin save

Source: http://cordova.apache.org/news/2014/07/10/tools-release.html

资料来源:http://cordova.apache.org/news/2014/07/10/tools-release.html

#3


8  

Since Cordova 5.0, yes.

自Cordova 5.0以来,是的。

<?xml version='1.0' encoding='utf-8'?>
    ...
    <plugin name="cordova-plugin-console" spec="^1.0.0" />
    ...
</ xml>

Mass saving plugins on an existing project :

现有项目中的大量保存插件:

$ cordova plugin save

On a fresh install (or after a clean), you can add all plugins with :

在全新安装(或干净)之后,您可以添加以下所有插件:

$ cordova prepare

Adding / updating / removing can also be done via cli :

添加/更新/删除也可以通过cli完成:

$ cordova plugin add <plugin[@<version>] | directory | git_url> --save
$ cordova plugin update <plugin[@<version>] | directory | git_url> --save
$ cordova plugin remove <plugin> --save

There is no mass update for the moment. You can remove plugins directory then run a $cordova prepare.

暂时没有大规模更新。您可以删除插件目录然后运行$ cordova准备。

Sources :

资料来源:

#4


5  

Config.xml is mainly used by phonegap build.

Config.xml主要由phonegap构建使用。

If you're using phonegap 3 you should manage your plugins using the CLI:

如果您使用的是phonegap 3,则应使用CLI管理插件:

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git

The only config.xml you should edit is /www/config.xml, the others are automatically generated from that one when you build your project using:

您应该编辑的唯一config.xml是/www/config.xml,其他的是在您使用以下项目构建项目时从该项自动生成的:

$ phonegap build ios

#5


-2  

You may want to check this for accelermator plugin: Phonegap Acceleramator plugin.

你可能想检查一下这个加速器插件:Phonegap Acceleramator插件。

Also you can search there about any plugin you need

您也可以在那里搜索您需要的任何插件

#1


124  

I'm pretty sure the reason that you can still use the plugin is because you either edited the wrong config.xml or did not run the cordova command line tools to propagate your changes to the correct config.xml file that is actually used by the app.

我很确定您仍然可以使用该插件的原因是您编辑了错误的config.xml或者没有运行cordova命令行工具将您的更改传播到实际使用的正确config.xml文件应用程序。

There are multiple config.xml files in different spots in a Cordova 3.x project. I'll try to give you an overview of the different locations of the files and how you should interact with them. Keep in mind that this is what happens when you use the CLI (Command Line-interface) - I generated this directory structure by typing:

Cordova 3.x项目中的不同位置有多个config.xml文件。我将尝试概述文件的不同位置以及如何与它们进行交互。请记住,这是使用CLI(命令行界面)时发生的情况 - 我通过键入以下内容生成了此目录结构:

cordova create {MyApp}
cordova platform add android ios
cordova plugin add org.apache.cordova.network-information

Or prior to Cordova 3.1, replace the last line with:

或者在Cordova 3.1之前,将最后一行替换为:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git

If you use just the platform level shell scripts to build the app (the "old" way that we did in Cordova 2.X), you can generally use the same workflow, but will need to Use Plugman to Manage Plugins. (We are in the process of documenting these two different "workflows".)

如果您仅使用平台级shell脚本来构建应用程序(我们在Cordova 2.X中执行的“旧”方式),您通常可以使用相同的工作流程,但需要使用Plugman来管理插件。 (我们正在记录这两个不同的“工作流程”。)

First, when you create an app with cordova create MyApp, it will create an empty project structure like this:

首先,当您使用cordova创建一个创建MyApp的应用程序时,它将创建一个如下所示的空项目结构:

/myApp/
        /www/           # This is where your "cross-platform' files go.
                        # The build tools copy these files over to the correct
                        # asset folder for each platform, like /assets/www/ for
                        # android or just /www/ for iOs. This is where you should
                        # be doing most/all of your work and is what should
                        # probably be version controlled.
        /platforms/
            /android/   # These will only appear after `cordova platform add`
            /ios/       # You should generally not touch these file as they are
                        # recreated quite often, although changes will persist.
        /plugins/
            /android/   # These will only appear after `cordova plugin add`. They
                        # pretty much just contain the native and web plugin code
                        # for all platforms that a plugin supports.
            /ios/
        /merges/        # This is where you can place platform-specific code that
                        # you write that will get merged in with your cross
                        # platform source, see the "customize each platform"
                        # section of: http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html

You should make all of your changes to files in /www/, which is the "cross platform" source code. Whatever is in this folder will generally get copied and propagated to the platform level www folder when you use the command line tools (whether its /assets/www for Android or just /www/ for iOS). This way, you only need a single source folder for your app - this is the folder that you should have under version control. Any app-wide configuration changes that you want should be made to the config.xml file placed at this location; later when you use the tools, this config.xml file will be copied (and sometimes modified with platform-specific configuration information) to the appropriate place for each app, like /platforms/android/res/xml/config.xml (for android) or /platforms/ios/AppName/config.xml (for iOS).

您应该对/ www /中的文件进行所有更改,这是“跨平台”源代码。当您使用命令行工具时(无论是针对Android的/ assets / www还是仅针对iOS的/ www /),此文件夹中的任何内容通常都会被复制并传播到平台级www文件夹。这样,您只需要一个应用程序的单个源文件夹 - 这是您在版本控制下应具有的文件夹。您想要的所有应用程序范围的配置更改都应该放在此位置的config.xml文件中;稍后当您使用这些工具时,此config.xml文件将被复制(有时会使用特定于平台的配置信息进行修改)到每个应用的适当位置,例如/platforms/android/res/xml/config.xml(用于android )或/platforms/ios/AppName/config.xml(适用于iOS)。

Say you want to add the acceleration plugin by typing cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git. If you were to run a diff after this command, you will see the following files have been changed or added:

假设您要通过键入cordova plugin添加https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git来添加加速插件。如果您在此命令后运行diff,您将看到以下文件已被更改或添加:

plugins/org.apache.cordova.network-information/ - This new folder contains all of the plugin meta information and code, including web and native code, for each supported platform

plugins / org.apache.cordova.network-information / - 这个新文件夹包含每个支持平台的所有插件元信息和代码,包括Web和本机代码

plugins/android.json and plugins/ios.json - Both of these files have been edited now to contain a reference to the network-information plugin. This is where you will see the config-munge bit of JSON. As you add more plugins, this file will continuously grow to reference all of them. This file tells the command line tools what code it needs to replace and in which files. For example, after adding the cordova-plugin-network-information plugin, you will see this in /plugins/android.json:

plugins / android.json和plugins / ios.json - 现在已经编辑了这两个文件,以包含对网络信息插件的引用。在这里您将看到JSON的config-munge位。随着您添加更多插件,此文件将不断增长以引用所有插件。该文件告诉命令行工具需要替换的代码和文件。例如,在添加cordova-plugin-network-information插件后,您将在/plugins/android.json中看到:

{
        "prepare_queue": {
            "installed": [],
            "uninstalled": []
        },
        "config_munge": {
            "res/xml/config.xml": {
                "/*": {
                    "<feature name=\"NetworkStatus\"><param name=\"android-package\" value=\"org.apache.cordova.networkinformation.NetworkManager\" /></feature>": 1
                }
            },
            "AndroidManifest.xml": {
                "/*": {
                    "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />": 1
                }
            }
        },
        "installed_plugins": {
            "org.apache.cordova.network-information": {
                "PACKAGE_NAME": "io.cordova.hellocordova"
            }
        },
        "dependent_plugins": {}
    }

This tells the scripts to write the feature name into res/xml/config.xml (again, for iOS, this will be different, since the app level config file is in a different location on iOS!), and also tells it to write android.permission.ACCESS_NETWORK_STATE permission into AndroidManifest.xml (you won't find anything like this on iOS since no permissions are necessary.) (By the way, what gets written to each of these json files is defined in the plugin's plugin.xml file.)

这告诉脚本将功能名称写入res / xml / config.xml(同样,对于iOS,这将是不同的,因为应用程序级别配置文件位于iOS上的不同位置!),并且还告诉它写入android.permission.ACCESS_NETWORK_STATE权限进入AndroidManifest.xml(你不会在iOS上找到这样的东西,因为不需要权限。)(顺便说一句,在插件的plugin.xml中定义了写入每个json文件的内容文件。)

platforms/android/AndroidManifest.xml - The CLI tools took care of adding whichever permission were defined in the plugin's xml file to AndoridManifest. Yes, this happens when you do cordova plugin add. These permissions are directly copied from whatever is in the plugins/android.json file. These permissions are also deleted when you 'rm' a plugin. However, editing these files is done intelligenty, in that you can add custom things to AndroidManifest.xml and they will persist.

platforms / android / AndroidManifest.xml - CLI工具负责将插件的xml文件中定义的任何权限添加到AndoridManifest。是的,当你执行cordova插件添加时会发生这种情况。这些权限直接从plugins / android.json文件中的任何内容复制。当你'插件'时,这些权限也会被删除。但是,编辑这些文件是智能的,因为您可以将自定义内容添加到AndroidManifest.xml,它们将保持不变。

platforms/android/assets/www/cordova_plugins.js - This file is buried inside the html resources that will make up your final app - these resources (pretty much anything in /platforms/) should not be edited by you because they will be replaced by the CLI tools quite frequently. This file is used by Cordova at runtime to load the plugin code that you added; it also takes care of mapping the JavaScript namespaces to the actual files (this is the "clobbers" declaration.) For example, I see:

platforms / android / assets / www / cordova_plugins.js - 这个文件隐藏在构成你最终应用程序的html资源里面 - 这些资源(/ platforms /中的几乎任何东西)都不应该由你编辑,因为它们会被替换通过CLI工具非常频繁。 Cordova在运行时使用此文件来加载您添加的插件代码;它还负责将JavaScript命名空间映射到实际文件(这是“clobbers”声明。)例如,我看到:

{
    "file": "plugins/org.apache.cordova.network-information/www/network.js",
    "id": "org.apache.cordova.network-information.network",
    "clobbers": [
        "navigator.connection",
        "navigator.network.connection"
    ]
}

this means that in your app code, navigator.connection and navigator.network.connection will both map to the code contained in plugins/org.apache.cordova.network-information/www/network.js.

这意味着在您的应用程序代码中,navigator.connection和navigator.network.connection都将映射到plugins / org.apache.cordova.network-information / www / network.js中包含的代码。

platforms/android/res/xml/config.xml - This is the platform-level config.xml file for Android. This file gets created by the CLI tools. A lot of the information that you write in your top level config.xml (/MyApp/www/config.xml) will get copied here, but not all of it (and there is some additional stuff, I'm not exactly sure where the additional stuff comes from.) This is the file that gets read by Android when it is running your app and it needs to check your config data. For example, Cordova Android code will use this to see which plugins are installed and which native classes map to which namespaces. I think the only way you could edit this is by using the /merges/ folder that I mentioned above.

platforms / android / res / xml / config.xml - 这是Android的平台级config.xml文件。此文件由CLI工具创建。您在*config.xml(/MyApp/www/config.xml)中编写的大量信息将在此处复制,但不是全部(并且还有一些其他内容,我不确定在哪里额外的东西来自。)这是Android在运行你的应用程序时读取的文件,它需要检查你的配置数据。例如,Cordova Android代码将使用它来查看安装了哪些插件以及哪些本机类映射到哪些命名空间。我认为你可以编辑的唯一方法是使用我上面提到的/ merges /文件夹。

platforms/ios/{AppName}.xcodeprojcj/project.pbxproj - The iOS equivalent of AndroidManifest.xml

platforms / ios / {AppName} .xcodeprojcj / project.pbxproj - 相当于AndroidManifest.xml的iOS

platforms/ios/{AppName}/config.xml - This is the platform-level config.xml file for iOS. See how it is in a different spot than on Android? (eg, not in /res/xml/config.xml?) This file automatically gets updated by the CLI and you should not touch it.

platforms / ios / {AppName} /config.xml - 这是iOS的平台级config.xml文件。了解它与Android不同的地方? (例如,不在/res/xml/config.xml中?)CLI会自动更新此文件,您不应该触摸它。

platforms/ios/www/cordova_plugins.js - The same file exists on Android (but in a different location) and has the same purpose: to help Cordova load your plugins at run time when somebody is using the app

platforms / ios / www / cordova_plugins.js - Android上存在相同的文件(但位于不同的位置)并且具有相同的目的:当有人使用应用程序时,帮助Cordova在运行时加载插件

I think that pretty much describes all of the files and folders that are used in a cordova project.

我认为这几乎描述了cordova项目中使用的所有文件和文件夹。

Hopefully now you can see that you should in fact only be editing the /www/config.xml file. This file will be used to construct the /platforms/android/res/xml/config.xml and /platforms/ios/{AppName}/config.xml, which are used by Cordova when the packaged app is running. Parts of this file will be used to edit the AndroidManifest.xml and project.pbxprojc files (for Android and iOS, respectively.)

希望现在你可以看到你实际上只应该编辑/www/config.xml文件。此文件将用于构造/platforms/android/res/xml/config.xml和/platforms/ios/{AppName}/config.xml,它们在打包的应用程序运行时由Cordova使用。此文件的一部分将用于编辑AndroidManifest.xml和project.pbxprojc文件(分别用于Android和iOS)。

This explains why you were still able to use the accelerometer in your app even after deleting the <feature name="Accelerometer"> lines - they were just being recopied into the platform level config.xml from the main app wide config.xml

这解释了为什么即使在删除 行之后您仍然可以在应用程序中使用加速度计 - 它们只是从主应用程序范围的config.xml重新复制到平台级别config.xml中

I guess the only thing left to figure out is how you can edit platform specific configuration files; for example, how can you edit the AndroidManifest.xml file? Well, it turns out that you can just edit the /platforms/android/AndroidManifest.xml file directly - the CLI is smart enough to not erase your customizations when it automatically adds or removes plugin permissions. So say for some reason you needed to support a lower version of Android than what Cordova supports, you can just change the object and it will persist though your cordova plugin add|rm {id} calls.

我想唯一要弄清楚的是如何编辑特定于平台的配置文件;例如,如何编辑AndroidManifest.xml文件?好吧,事实证明你可以直接编辑/platforms/android/AndroidManifest.xml文件 - CLI足够聪明,在自动添加或删除插件权限时不会删除自定义。所以说出于某些原因你需要支持比Cordova支持的更低版本的Android,你可以只更改对象,它会持续存在但你的cordova插件添加| rm {id}调用。

I hope that clarifies things, feel free to ask any more questions!

我希望澄清事情,随时提出更多问题!

#2


22  

Since cordova 3.5, we can persist plugins in config.xml file

从cordova 3.5开始,我们可以在config.xml文件中保存插件

<feature name="Network Information">
    <param name="id" value="org.apache.cordova.network-information" />
    <param name="version" value="0.2.10" />
</feature>

The following command will fetch the plugins defined in config.xml

以下命令将获取config.xml中定义的插件

cordova restore plugins --experimental

The following command will write your current installed plugins in config.xml (3.5):

以下命令将在config.xml(3.5)中编写当前安装的插件:

cordova save plugins --experimental

In 5.x and later:

在5.x及更高版本中:

cordova plugin save

Source: http://cordova.apache.org/news/2014/07/10/tools-release.html

资料来源:http://cordova.apache.org/news/2014/07/10/tools-release.html

#3


8  

Since Cordova 5.0, yes.

自Cordova 5.0以来,是的。

<?xml version='1.0' encoding='utf-8'?>
    ...
    <plugin name="cordova-plugin-console" spec="^1.0.0" />
    ...
</ xml>

Mass saving plugins on an existing project :

现有项目中的大量保存插件:

$ cordova plugin save

On a fresh install (or after a clean), you can add all plugins with :

在全新安装(或干净)之后,您可以添加以下所有插件:

$ cordova prepare

Adding / updating / removing can also be done via cli :

添加/更新/删除也可以通过cli完成:

$ cordova plugin add <plugin[@<version>] | directory | git_url> --save
$ cordova plugin update <plugin[@<version>] | directory | git_url> --save
$ cordova plugin remove <plugin> --save

There is no mass update for the moment. You can remove plugins directory then run a $cordova prepare.

暂时没有大规模更新。您可以删除插件目录然后运行$ cordova准备。

Sources :

资料来源:

#4


5  

Config.xml is mainly used by phonegap build.

Config.xml主要由phonegap构建使用。

If you're using phonegap 3 you should manage your plugins using the CLI:

如果您使用的是phonegap 3,则应使用CLI管理插件:

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git

The only config.xml you should edit is /www/config.xml, the others are automatically generated from that one when you build your project using:

您应该编辑的唯一config.xml是/www/config.xml,其他的是在您使用以下项目构建项目时从该项自动生成的:

$ phonegap build ios

#5


-2  

You may want to check this for accelermator plugin: Phonegap Acceleramator plugin.

你可能想检查一下这个加速器插件:Phonegap Acceleramator插件。

Also you can search there about any plugin you need

您也可以在那里搜索您需要的任何插件