If a phonegap plugin is declared in config.xml?

I am new to the development of telephone conversations, so I have a few questions:

1) I am using the accelerometer plugin. I read in the manual that I need to declare a plugin in the config.xml file in order to use it. However, I noticed that even if I delete the ad from the config.xml file

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

The accelerometer is still running.

Therefore, I would like to ask you if the use of the config.xml file is deprecated in phonegap 3.0.0. If this is the case, then where is the binding?

2) I use the android platform to create an application. There are three config.xml files in the project structure with different content:

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

What is the use of each of them? Where do I expect to announce my traffic jam? I did this in res / xml / config / xml

thank

+44
cordova phonegap-plugins cordova-3
01 Oct '13 at 9:21 on
source share
5 answers

I'm sure the reason you can still use the plugin is because you either edited the wrong config.xml or you didn't run the cordova command-line tools to propagate your changes to the correct config.xml file, which is actually used by the application.

There are several config.xml files in different places in the Cordova 3.x project. I will try to give you an overview of the different file locations and how you should interact with them. Keep in mind that this happens when you use the CLI ( Command Line Interface ). I created this directory structure by typing:

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

Or before Cordoba 3.1, replace the last line as follows:

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

If you use only platform-level shell scripts to create the application (the “old” way we did in Cordova 2.X), you can usually use the same workflow, but it needs to Use Plugman to manage the plugins . (We are in the process of documenting these two different “workflows.")

Firstly, when creating an application with cordova create MyApp it will create an empty project structure as follows:

 /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 must make all your changes to the files in /www/ , which is the cross-platform source code. Everything in this folder will usually be copied and distributed to the www platform using the command line tools (be it /assets/www for Android or just /www/ for iOS). Thus, you only need one source folder for your application - this is the folder that you must have when managing versions. Any changes to the configuration of the application as a whole that you want should be made to the config.xml file located in this place; later, when you use the tools, this config.xml file will be copied (and sometimes modified with configuration information on the platform) to the appropriate location for each application, for example /platforms/android/res/xml/config.xml (for android) or /platforms/ios/AppName/config.xml (for iOS).

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

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

/android.json plugins and /ios.json plugins - Both of these files have now been edited to contain a link to the network information plugin. Here you will see the JSON configuration bit. When you add more plugins, this file will constantly grow to reference all of them. This file tells the command line tools which code to replace and in which files. For example, after adding the plugin cordova-plugin-network-info you will see this in /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 function name in res/xml/config.xml (again, for iOS it will be different, since the application-level configuration file is in a different location on iOS!), And also tells it to write android.permission.ACCESS_NETWORK_STATE to AndroidManifest.xml (you will not find anything similar on iOS, since no permissions are required.) (By the way, what is written to each of these json files is defined in the plugin plugin.xml file.)

platforms /Android/AndroidManifest.xml - CLI tools have taken care to add any permission defined in the plugin xml file to AndoridManifest. Yes, this happens when you do the cordova plugin add . These permissions are directly copied from the plugins / android.json file. These permissions are also removed when you have the 'rm' plugin. However, editing these files is done intelligently, as you can add custom things to AndroidManifest.xml and they will be saved.

platforms / Android / assets / WWW / cordova_plugins.js - This file is similar to the html resources that will make up your final application - these resources (almost nothing in / platform /) should not be edited by you because they will be replaced by CLI tools rather often. This file is used by Cordova at run time to load the added plugin code; he also takes care of matching JavaScript namespaces with actual files (this is the declaration of "clobbers"). For example, I see:

 { "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 application code navigator.connection and navigator.network.connection code contained in plugins/org.apache.cordova.network-information/www/network.js will be displayed.

platforms /Android/RES/XML/config.xml - This is the platform level config.xml file for Android. This file is created by the CLI tools. Most of the information you write at your top level config.xml (/MyApp/www/config.xml) will be copied here, but not all (and there are some additional things, I'm not quite sure where the additional material comes from.) This is the file that Android reads when it launches your application, and it needs to check your configuration data. For example, Cordoba Android code will use this to see which plugins are installed and which native classes map to those namespaces. I think the only way you could edit this is to use / merges / folder, which I mentioned above.

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

platforms / iOS / {AppName} /config.xml - This is the config.xml configuration file on the iOS platform. See how this happens elsewhere than on Android? (for example, not in /res/xml/config.xml?) This file is automatically updated by the CLI, and you should not touch it.

platforms / iOS / WWW / cordova_plugins.js - The same file exists on Android (but in a different place) and has the same goal: to help Cordoba load your plugins at runtime when someone uses the application

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

Hopefully now you will see that you should actually edit the /www/config.xml file. This file will be used to create the /platforms/android/res/xml/config.xml and /platforms/ios/{AppName}/config.xml that Cordona uses when launching the packaged application. Parts of this file will be used to edit the AndroidManifest.xml and project.pbxprojc files (for Android and iOS, respectively.)

This explains why you could still use the accelerometer in your application even after deleting the <feature name="Accelerometer"> lines - they were simply rewritten to the platform level config.xml from the main application config.xml

I think that it remains only to find out how you can edit the configuration files on the platform; for example, how can you edit the AndroidManifest.xml file? Well, it turns out that you can simply edit the /platforms/android/AndroidManifest.xml file directly - the CLI is smart enough not to erase your settings when it automatically adds or removes the permissions of the plugin. Therefore, for some reason you need to support a lower version of Android than Cordoba supports, you can just change the object and it will be saved, although your calls are cordova plugin add|rm {id} .

I hope this clarifies the situation, feel free to ask more questions!

+124
01 Oct '13 at 21:00
source share

Since cordova 3.5 , we can save plugins in 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 extract the plugins defined in the config.xml file

 cordova restore plugins --experimental 

The following command will record the currently installed plugins in the config.xml (3.5) file:

 cordova save plugins --experimental 

In 5.x and later:

 cordova plugin save 

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

+22
Aug 03 '14 at 2:36 on
source share

Since Cordoba 5.0, yes .

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

Scalable plugins in an existing project:

 $ cordova plugin save 

In a new installation (or after cleaning) you can add all the plugins with:

 $ cordova prepare 

Adding / updating / deleting can also be done using 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 currently no bulk update. You can delete the plugins directory, then run $cordova prepare .

Sources:

+8
Aug 18 '15 at 13:56 on
source share

Config.xml is mainly used to build phonegap.

If you are using phonegap 3, you must manage your plugins using the CLI:

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

The only config.xml file you need to change is /www/config.xml, the rest are automatically generated from it when you create the project, using:

 $ phonegap build ios 
+5
Oct 01 '13 at 9:30
source share

You can check this for the accelerator plugin: Acceleramator plugin for Phonegap .

You can also search for any plugin you need there.

-2
Oct. 01 '13 at 11:16
source share



All Articles