Manually install Device plugin (and others) into cordova 3.0

邮差的信 提交于 2020-01-10 08:29:28

问题


Phonegap/Cordova 3.0 has moved into a modular design starting with version 3.0. For example, to call the device.version API, you need to include the Device plugin into your project.

Anyone can provide me with clear instructions on how to install the Device (or any other) cordova API plugin into a new iOS project (using XCode) AND Android (using Eclipse)?

All I could find is details using Node.js and/or PlugMan. Needing an automated script to do the basic job of adding a plugin is undesirable to me, as I do not like processes doing things I don't understand (behind the scene).

In the past (cordova 2.9), I did the following to add a third-party plugin in (say Android) that worked perfectly:

  1. Put the plugin .java code into the /src folder
  2. Put the plugin .js code in my www folder
  3. Import the .js file into index.html
  4. Add the feature tag in config.xml
  5. Call the plugin in Javascript

I never added plugins in iOS before.

However, I assumed the above process should work just fine for cordova-based plugins, but it did not. Up to this point, I did not try Android, but I tried iOS with no luck.

I included CDVDevice.h and CDVDevice.m in /plugins folder. Also I imported the device.js into index.html, and modified config.xml! I will try Android only after finishing iOS.

Please, if you know how to do this manually let me know.

Thank you in advance.


回答1:


You can do it this way, download the plugin locally to your machine then run this code

cordova plugin add <id located in plugin.xml> --searchpath <local path to plugin>

This will install the plugin into your project




回答2:


I ran into the same issue.

In fact, the plugin system has not changed much.

I added the date picker plugin for Android just now :

  • add classes (.m .h for iphone, .java for android)
  • add js files where you want
  • add link to js files in your index.html
  • edit config.xml (path depends on which OS you used) :

Instead of adding plugins between plugins tags :

<plugin name="DatePickerPlugin" value="com.phonegap.plugins.DatePickerPlugin"/>

You will add a feature (what a revolution !) like this :

<feature name="DatePickerPlugin" >
    <param name="android-package" value="com.phonegap.plugins.DatePickerPlugin"/>
</feature>

And that is it !

If you are not sure about the OS syntax for param name, you can add a default cordova plugin using a command as this one :

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

More info there : http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface




回答3:


I was getting an error when I tried to add a plugin using the following command:

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

Although, git clone was working, so I downloaded the plugin into a local folder and added it by using

cordova plugin add my/local/folder



回答4:


For Android we just need to create the plugin (Java class extending CordovaPlugin) and then add the item into config.xml (res/xml/..) you are done.

 <feature name="Calendar">
        <param name="android-package" value="com.package.Calendar" />
    </feature>

assume Calendar as your plugin name Also make sure to add link to js file

Thanks



来源:https://stackoverflow.com/questions/17778032/manually-install-device-plugin-and-others-into-cordova-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!